Cleanup previous PR

This commit is contained in:
Kovid Goyal 2025-07-12 13:11:53 +05:30
parent fe0a0a63b8
commit 2ee11ed613
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 20 additions and 12 deletions

View file

@ -111,6 +111,10 @@ Detailed list of changes
- A new :ref:`protocol extension <mouse_leave_window>` to notify terminal programs that have turned on SGR Pixel mouse reporting when the mouse leaves the window (:disc:`8808`)
- A new :option:`launch --hold-after-ssh` to not close a launched window
that connects directly to a remote host because of
:option:`launch --cwd`:code:`=current` when the connection ends (:pull:`8807`)
- Fix :opt:`remember_window_position` not working because of a stupid typo (:iss:`8646`)
- A new :option:`kitty --grab-keyboard` that can be used to grab the keyboard so that global shortcuts are sent to kitty instead

View file

@ -140,8 +140,10 @@ def options_spec() -> str:
oldest foreground process associated with the currently active window rather
than the newest foreground process. Finally, the special value :code:`root`
refers to the process that was originally started when the window was created.
When running :code:`kitten ssh`, using :option:`--hold-after-ssh` will cause a shell
in the working directory that started the :code:`kitten ssh` to be opened after disconnecting.
When opening in the same working directory as the current window causes the new
window to connect to a remote host, you can use the :option:`--hold-after-ssh`
flag to prevent the new window from closing when the connection is terminated.
--env
@ -399,7 +401,9 @@ def options_spec() -> str:
--hold-after-ssh
type=bool-set
When using :option:`--cwd=current` from a kitten ssh session, after disconnecting from the session on the new window, a shell will spawn.
When using :option:`--cwd`:code:`=current` or similar from a window that is running the ssh kitten,
the new window will run a local shell after disconnecting from the remote host, when this option
is specified.
"""
@ -668,8 +672,8 @@ def _launch(
else:
kw['cwd'] = opts.cwd
if opts.hold_after_ssh:
if opts.cwd != 'current':
raise ValueError("--hold_after_ssh can only be supplied if --cwd=current is also supplied")
if opts.cwd not in ('current', 'last_reported', 'oldest'):
raise ValueError("--hold-after-ssh can only be supplied if --cwd=current or similar is also supplied")
kw['hold_after_ssh'] = True
if opts.location != 'default':

View file

@ -57,7 +57,7 @@ class Launch(RemoteCommand):
watcher/list.str: list of paths to watcher files
bias/float: The bias with which to create the new window in the current layout
wait_for_child_to_exit/bool: Boolean indicating whether to wait and return child exit code
hold_after_ssh/bool: Boolean indicating whether to spawn a shell after exiting a kitten ssh opened by this launch, requires --cwd=current to also be supplied
hold_after_ssh/bool: Boolean indicating whether to run a local shell after exiting the ssh session cloned via cwd=current or similar
'''
short_desc = 'Run an arbitrary process in a new window/tab'

View file

@ -167,14 +167,12 @@ def modify_argv_for_launch_with_cwd(self, argv: list[str], env: dict[str, str] |
server_args = [] if run_shell else list(argv)
from kittens.ssh.utils import set_cwd_in_cmdline, set_env_in_cmdline, set_server_args_in_cmdline
if ssh_kitten_cmdline and ssh_kitten_cmdline[0] == 'kitten':
if hold_after_ssh:
argv[:] = [kitten_exe(), "run-shell", kitten_exe()] +ssh_kitten_cmdline[1:]
else:
argv[:] = [kitten_exe()]+ssh_kitten_cmdline[1:]
else:
argv[:] = ssh_kitten_cmdline
ssh_kitten_cmdline[0] = kitten_exe()
argv[:] = ssh_kitten_cmdline
set_cwd_in_cmdline(reported_cwd, argv)
set_server_args_in_cmdline(server_args, argv, allocate_tty=not run_shell)
if hold_after_ssh:
argv[:0] = [kitten_exe(), "run-shell"]
if env is not None:
# Assume env is coming from a local process so drop env
# vars that can cause issues when set on the remote host
@ -1784,6 +1782,8 @@ def ssh_kitten_cmdline(self) -> list[str]:
from kittens.ssh.utils import is_kitten_cmdline
for p in self.child.foreground_processes:
q = list(p['cmdline'] or ())
if len(q) > 3 and os.path.basename(q[0]) == 'kitten' and q[1] == 'run-shell':
q = q[2:] # --hold-after-ssh causes kitten run-shell wrapper to be added
if is_kitten_cmdline(q):
return q
return []