Have *_with_cwd work with the ssh kitten to open new windows auto-logged into the remote server at the current remote working directory

This commit is contained in:
Kovid Goyal
2022-03-15 19:59:16 +05:30
parent a216f6bd46
commit ce1e22ac95
6 changed files with 63 additions and 5 deletions

View File

@@ -42,6 +42,27 @@ from .copy import CopyInstruction
from .options.types import Options as SSHOptions
from .options.utils import DELETE_ENV_VAR
def is_kitten_cmdline(q: List[str]) -> bool:
if len(q) < 4:
return False
if os.path.basename(q[0]).lower() != 'kitty':
return False
return q[1:3] == ['+kitten', 'ssh'] or q[1:4] == ['+', 'kitten', 'ssh']
def set_cwd_in_cmdline(cwd: str, argv: List[str]) -> None:
for i, arg in enumerate(tuple(argv)):
if arg.startswith('--kitten=cwd'):
argv[i] = f'--kitten=cwd={cwd}'
return
elif i > 0 and argv[i-1] == '--kitten' and (arg.startswith('cwd=') or arg.startswith('cwd ')):
argv[i] = cwd
return
idx = argv.index('ssh')
argv.insert(idx + 1, f'--kitten=cwd={cwd}')
# See https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
quote_pat = re.compile('([\\`"\n])')