This commit is contained in:
Kovid Goyal 2022-03-15 22:12:49 +05:30
parent 1fbb4f763e
commit 82de6a1c56
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -10,6 +10,7 @@ import os
import re
import secrets
import shlex
import shutil
import stat
import subprocess
import sys
@ -43,6 +44,11 @@ from .options.types import Options as SSHOptions
from .options.utils import DELETE_ENV_VAR
@run_once
def ssh_exe() -> str:
return shutil.which('ssh') or 'ssh'
def is_kitten_cmdline(q: List[str]) -> bool:
if len(q) < 4:
return False
@ -368,7 +374,7 @@ class InvalidSSHArgs(ValueError):
def system_exit(self) -> None:
if self.err_msg:
print(self.err_msg, file=sys.stderr)
os.execlp('ssh', 'ssh')
os.execlp(ssh_exe(), 'ssh')
def parse_ssh_args(args: List[str], extra_args: Tuple[str, ...] = ()) -> Tuple[List[str], List[str], bool, Tuple[str, ...]]:
@ -524,7 +530,7 @@ def dcs_to_kitty(payload: Union[bytes, str], type: str = 'ssh') -> bytes:
@run_once
def ssh_version() -> Tuple[int, int]:
o = subprocess.check_output(['ssh', '-V'], stderr=subprocess.STDOUT).decode()
o = subprocess.check_output([ssh_exe(), '-V'], stderr=subprocess.STDOUT).decode()
m = re.match(r'OpenSSH_(\d+).(\d+)', o)
if m is None:
raise ValueError(f'Invalid version string for OpenSSH: {o}')
@ -560,7 +566,7 @@ def drain_potential_tty_garbage(p: 'subprocess.Popen[bytes]', data_request: str)
def run_ssh(ssh_args: List[str], server_args: List[str], found_extra_args: Tuple[str, ...]) -> NoReturn:
cmd = ['ssh'] + ssh_args
cmd = [ssh_exe()] + ssh_args
hostname, remote_args = server_args[0], server_args[1:]
if not remote_args:
cmd.append('-t')