Allow configuring the interpreter to use on the remote host

This commit is contained in:
Kovid Goyal 2022-03-04 12:18:27 +05:30
parent 95efeee7de
commit fe27ee2d79
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 18 additions and 6 deletions

View File

@ -26,6 +26,7 @@ from kitty.types import run_once
from kitty.utils import SSHConnectionData from kitty.utils import SSHConnectionData
from .completion import complete, ssh_options from .completion import complete, ssh_options
from .config import options_for_host
from .options.types import Options as SSHOptions from .options.types import Options as SSHOptions
from .options.utils import DELETE_ENV_VAR from .options.utils import DELETE_ENV_VAR
@ -115,7 +116,6 @@ def load_ssh_options() -> Dict[str, SSHOptions]:
def get_ssh_data(msg: str, ssh_opts: Optional[Dict[str, SSHOptions]] = None) -> Iterator[bytes]: def get_ssh_data(msg: str, ssh_opts: Optional[Dict[str, SSHOptions]] = None) -> Iterator[bytes]:
from .config import options_for_host
record_sep = b'\036' record_sep = b'\036'
if ssh_opts is None: if ssh_opts is None:
@ -319,7 +319,7 @@ def parse_ssh_args(args: List[str]) -> Tuple[List[str], List[str], bool]:
return ssh_args, server_args, passthrough return ssh_args, server_args, passthrough
def get_posix_cmd(remote_args: List[str]) -> List[str]: def get_remote_command(remote_args: List[str], hostname: str = 'localhost', interpreter: str = 'sh') -> List[str]:
command_to_execute = '' command_to_execute = ''
if remote_args: if remote_args:
# ssh simply concatenates multiple commands using a space see # ssh simply concatenates multiple commands using a space see
@ -328,7 +328,7 @@ def get_posix_cmd(remote_args: List[str]) -> List[str]:
args = [c.replace("'", """'"'"'""") for c in remote_args] args = [c.replace("'", """'"'"'""") for c in remote_args]
command_to_execute = "exec \"$login_shell\" -c '{}'".format(' '.join(args)) command_to_execute = "exec \"$login_shell\" -c '{}'".format(' '.join(args))
sh_script = load_script(exec_cmd=command_to_execute) sh_script = load_script(exec_cmd=command_to_execute)
return [f'sh -c {shlex.quote(sh_script)}'] return [f'{interpreter} -c {shlex.quote(sh_script)}']
def main(args: List[str]) -> NoReturn: def main(args: List[str]) -> NoReturn:
@ -348,8 +348,8 @@ def main(args: List[str]) -> NoReturn:
cmd.append('-t') cmd.append('-t')
cmd.append('--') cmd.append('--')
cmd.append(hostname) cmd.append(hostname)
f = get_posix_cmd hostname_for_match = hostname.split('@', 1)[-1].split(':', 1)[0]
cmd += f(remote_args) cmd += get_remote_command(remote_args, hostname, options_for_host(hostname_for_match, load_ssh_options()).interpreter)
os.execvp('ssh', cmd) os.execvp('ssh', cmd)

View File

@ -70,6 +70,14 @@ are processed alphabetically. The special value :code:`_kitty_copy_env_var_`
will cause the value of the variable to be copied from the local machine. will cause the value of the variable to be copied from the local machine.
''') ''')
opt('interpreter', 'sh', long_text='''
The interpreter to use on the remote host. Must be either a POSIX complaint shell
or a python executable. If the default sh is not available for broken, using
an alternate interpreter can be useful. Note that as the interpreter is used for
bootstrapping, hostname specific values are matched again the hostname from the
command line args rather than the actual remote hostname.
''')
opt('remote_dir', '.local/share/kitty-ssh-kitten', option_type='relative_dir', long_text=''' opt('remote_dir', '.local/share/kitty-ssh-kitten', option_type='relative_dir', long_text='''
The location on the remote computer where the files needed for this kitten The location on the remote computer where the files needed for this kitten
are installed. The location is relative to the HOME directory. Absolute paths or paths are installed. The location is relative to the HOME directory. Absolute paths or paths

View File

@ -18,6 +18,9 @@ class Parser:
def hostname(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def hostname(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
hostname(val, ans) hostname(val, ans)
def interpreter(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['interpreter'] = str(val)
def remote_dir(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def remote_dir(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['remote_dir'] = relative_dir(val) ans['remote_dir'] = relative_dir(val)

View File

@ -5,11 +5,12 @@ import kittens.ssh.copy
option_names = ( # {{{ option_names = ( # {{{
'copy', 'env', 'hostname', 'remote_dir', 'shell_integration') # }}} 'copy', 'env', 'hostname', 'interpreter', 'remote_dir', 'shell_integration') # }}}
class Options: class Options:
hostname: str = '*' hostname: str = '*'
interpreter: str = 'sh'
remote_dir: str = '.local/share/kitty-ssh-kitten' remote_dir: str = '.local/share/kitty-ssh-kitten'
shell_integration: str = 'inherit' shell_integration: str = 'inherit'
copy: typing.Dict[str, kittens.ssh.copy.CopyInstruction] = {} copy: typing.Dict[str, kittens.ssh.copy.CopyInstruction] = {}