mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-16 21:45:03 +02:00
More typing work
This commit is contained in:
@@ -7,6 +7,7 @@ import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import List, Tuple
|
||||
|
||||
SHELL_SCRIPT = '''\
|
||||
#!/bin/sh
|
||||
@@ -43,7 +44,8 @@ exec -a "-$shell_name" "$0"
|
||||
|
||||
|
||||
def get_ssh_cli():
|
||||
other_ssh_args, boolean_ssh_args = [], []
|
||||
other_ssh_args: List[str] = []
|
||||
boolean_ssh_args: List[str] = []
|
||||
raw = subprocess.Popen(['ssh'], stderr=subprocess.PIPE).stderr.read().decode('utf-8')
|
||||
for m in re.finditer(r'\[(.+?)\]', raw):
|
||||
q = m.group(1)
|
||||
@@ -56,11 +58,11 @@ def get_ssh_cli():
|
||||
return set('-' + x for x in boolean_ssh_args), set('-' + x for x in other_ssh_args)
|
||||
|
||||
|
||||
def parse_ssh_args(args):
|
||||
def parse_ssh_args(args: List[str]) -> Tuple[List[str], List[str], bool]:
|
||||
boolean_ssh_args, other_ssh_args = get_ssh_cli()
|
||||
passthrough_args = {'-' + x for x in 'Nnf'}
|
||||
ssh_args = []
|
||||
server_args = []
|
||||
server_args: List[str] = []
|
||||
expecting_option_val = False
|
||||
passthrough = False
|
||||
for arg in args:
|
||||
@@ -97,7 +99,7 @@ def parse_ssh_args(args):
|
||||
return ssh_args, server_args, passthrough
|
||||
|
||||
|
||||
def quote(x):
|
||||
def quote(x: str) -> str:
|
||||
# we have to escape unbalanced quotes and other unparsable
|
||||
# args as they will break the shell script
|
||||
# But we do not want to quote things like * or 'echo hello'
|
||||
@@ -117,8 +119,8 @@ def main(args):
|
||||
terminfo = subprocess.check_output(['infocmp']).decode('utf-8')
|
||||
sh_script = SHELL_SCRIPT.replace('TERMINFO', terminfo, 1)
|
||||
if len(server_args) > 1:
|
||||
command_to_execute = [quote(c) for c in server_args[1:]]
|
||||
command_to_execute = 'exec ' + ' '.join(command_to_execute)
|
||||
command_to_executeg = (quote(c) for c in server_args[1:])
|
||||
command_to_execute = 'exec ' + ' '.join(command_to_executeg)
|
||||
else:
|
||||
command_to_execute = ''
|
||||
sh_script = sh_script.replace('EXEC_CMD', command_to_execute)
|
||||
|
||||
Reference in New Issue
Block a user