diff --git a/docs/changelog.rst b/docs/changelog.rst index 47a083e59df..1d53741b39e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -42,6 +42,8 @@ Detailed list of changes - Fix a regression in 0.27.0 that broke kitty @ set-font-size 0 (:iss:`5992`) +- launch: When using ``--cwd=current`` for a remote system support running non shell commands as well (:disc:`5987`) + 0.27.1 [2023-02-07] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/ssh/utils.py b/kittens/ssh/utils.py index 069d1f15c40..540ec5d09de 100644 --- a/kittens/ssh/utils.py +++ b/kittens/ssh/utils.py @@ -121,7 +121,11 @@ def is_extra_arg(arg: str, extra_args: Tuple[str, ...]) -> str: passthrough_args = {f'-{x}' for x in 'NnfGT'} -def set_server_args_in_cmdline(server_args: List[str], argv: List[str], extra_args: Tuple[str, ...] = ('--kitten',)) -> None: +def set_server_args_in_cmdline( + server_args: List[str], argv: List[str], + extra_args: Tuple[str, ...] = ('--kitten',), + allocate_tty: bool = False +) -> None: boolean_ssh_args, other_ssh_args = get_ssh_cli() ssh_args = [] expecting_option_val = False @@ -136,6 +140,8 @@ def set_server_args_in_cmdline(server_args: List[str], argv: List[str], extra_ar if argument.startswith('-') and not expecting_option_val: if argument == '--': del ans[i+2:] + if allocate_tty and ans[i-1] != '-t': + ans.insert(i, '-t') break if extra_args: matching_ex = is_extra_arg(argument, extra_args) @@ -173,5 +179,7 @@ def set_server_args_in_cmdline(server_args: List[str], argv: List[str], extra_ar expecting_option_val = False continue del ans[i+1:] + if allocate_tty and ans[i] != '-t': + ans.insert(i, '-t') break argv[:] = ans + server_args diff --git a/kitty/launch.py b/kitty/launch.py index 0461dfaf777..7cadd3f8e01 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -432,6 +432,7 @@ def launch( force_target_tab: bool = False, active: Optional[Window] = None, is_clone_launch: str = '', + rc_from_window: Optional[Window] = None, ) -> Optional[Window]: active = active or boss.active_window_for_cwd if active: @@ -486,6 +487,8 @@ def launch( kw['cwd_from'] = CwdRequest(active, CwdRequestType.root) else: kw['cwd'] = opts.cwd + if kw['cwd_from'] is not None and rc_from_window is not None: + kw['cwd_from'].rc_from_window_id = rc_from_window.id if opts.location != 'default': kw['location'] = opts.location if opts.copy_colors and active: @@ -538,9 +541,10 @@ def launch( elif x == '@last-line-on-screen': x = str(screen.visual_line(screen.lines - 1) or '') final_cmd.append(x) - exe = which(final_cmd[0]) - if exe: - final_cmd[0] = exe + if rc_from_window is None and final_cmd: + exe = which(final_cmd[0]) + if exe: + final_cmd[0] = exe kw['cmd'] = final_cmd if force_window_launch and opts.type not in non_window_launch_types: opts.type = 'window' diff --git a/kitty/rc/launch.py b/kitty/rc/launch.py index 0f673da439e..497a7ce1585 100644 --- a/kitty/rc/launch.py +++ b/kitty/rc/launch.py @@ -91,7 +91,7 @@ def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: target_tab = tabs[0] elif payload_get('type') not in ('background', 'os-window', 'tab', 'window'): return None - w = do_launch(boss, opts, payload_get('args') or [], target_tab=target_tab) + w = do_launch(boss, opts, payload_get('args') or [], target_tab=target_tab, rc_from_window=window) return None if payload_get('no_response') else str(getattr(w, 'id', 0)) diff --git a/kitty/window.py b/kitty/window.py index c30b11259b0..76e4eaed60f 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -144,6 +144,7 @@ class CwdRequest: def __init__(self, window: Optional['Window'] = None, request_type: CwdRequestType = CwdRequestType.current) -> None: self.window_id = -1 if window is None else window.id self.request_type = request_type + self.rc_from_window_id = 0 def __bool__(self) -> bool: return self.window_id > -1 @@ -170,14 +171,15 @@ def modify_argv_for_launch_with_cwd(self, argv: List[str]) -> str: return '' reported_cwd = path_from_osc7_url(window.screen.last_reported_cwd) if window.screen.last_reported_cwd else '' if reported_cwd and (self.request_type is not CwdRequestType.root or window.root_in_foreground_processes): - # First check if we are running ssh kitten, and trying to open the configured login shell - if argv[0] == resolved_shell(get_options())[0]: - ssh_kitten_cmdline = window.ssh_kitten_cmdline() - if ssh_kitten_cmdline: - from kittens.ssh.utils import set_cwd_in_cmdline - argv[:] = ssh_kitten_cmdline - set_cwd_in_cmdline(reported_cwd, argv) - return '' + ssh_kitten_cmdline = window.ssh_kitten_cmdline() + if ssh_kitten_cmdline: + run_shell = argv[0] == resolved_shell(get_options())[0] + server_args = [] if run_shell else list(argv) + from kittens.ssh.utils import set_cwd_in_cmdline, set_server_args_in_cmdline + argv[:] = ssh_kitten_cmdline + set_cwd_in_cmdline(reported_cwd, argv) + set_server_args_in_cmdline(server_args, argv, allocate_tty=not run_shell) + return '' if not window.child_is_remote and (self.request_type is CwdRequestType.last_reported or window.at_prompt): return reported_cwd return window.get_cwd_of_child(oldest=self.request_type is CwdRequestType.oldest) or ''