DRYer
This commit is contained in:
parent
1fbb4f763e
commit
82de6a1c56
@ -10,6 +10,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
import shlex
|
import shlex
|
||||||
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -43,6 +44,11 @@ from .options.types import Options as SSHOptions
|
|||||||
from .options.utils import DELETE_ENV_VAR
|
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:
|
def is_kitten_cmdline(q: List[str]) -> bool:
|
||||||
if len(q) < 4:
|
if len(q) < 4:
|
||||||
return False
|
return False
|
||||||
@ -368,7 +374,7 @@ class InvalidSSHArgs(ValueError):
|
|||||||
def system_exit(self) -> None:
|
def system_exit(self) -> None:
|
||||||
if self.err_msg:
|
if self.err_msg:
|
||||||
print(self.err_msg, file=sys.stderr)
|
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, ...]]:
|
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
|
@run_once
|
||||||
def ssh_version() -> Tuple[int, int]:
|
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)
|
m = re.match(r'OpenSSH_(\d+).(\d+)', o)
|
||||||
if m is None:
|
if m is None:
|
||||||
raise ValueError(f'Invalid version string for OpenSSH: {o}')
|
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:
|
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:]
|
hostname, remote_args = server_args[0], server_args[1:]
|
||||||
if not remote_args:
|
if not remote_args:
|
||||||
cmd.append('-t')
|
cmd.append('-t')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user