Skip to content

Commit 2ee11ed

Browse files
committed
Cleanup previous PR
1 parent fe0a0a6 commit 2ee11ed

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ Detailed list of changes
111111

112112
- 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`)
113113

114+
- A new :option:`launch --hold-after-ssh` to not close a launched window
115+
that connects directly to a remote host because of
116+
:option:`launch --cwd`:code:`=current` when the connection ends (:pull:`8807`)
117+
114118
- Fix :opt:`remember_window_position` not working because of a stupid typo (:iss:`8646`)
115119

116120
- A new :option:`kitty --grab-keyboard` that can be used to grab the keyboard so that global shortcuts are sent to kitty instead

kitty/launch.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ def options_spec() -> str:
140140
oldest foreground process associated with the currently active window rather
141141
than the newest foreground process. Finally, the special value :code:`root`
142142
refers to the process that was originally started when the window was created.
143-
When running :code:`kitten ssh`, using :option:`--hold-after-ssh` will cause a shell
144-
in the working directory that started the :code:`kitten ssh` to be opened after disconnecting.
143+
144+
When opening in the same working directory as the current window causes the new
145+
window to connect to a remote host, you can use the :option:`--hold-after-ssh`
146+
flag to prevent the new window from closing when the connection is terminated.
145147
146148
147149
--env
@@ -399,7 +401,9 @@ def options_spec() -> str:
399401
400402
--hold-after-ssh
401403
type=bool-set
402-
When using :option:`--cwd=current` from a kitten ssh session, after disconnecting from the session on the new window, a shell will spawn.
404+
When using :option:`--cwd`:code:`=current` or similar from a window that is running the ssh kitten,
405+
the new window will run a local shell after disconnecting from the remote host, when this option
406+
is specified.
403407
"""
404408

405409

@@ -668,8 +672,8 @@ def _launch(
668672
else:
669673
kw['cwd'] = opts.cwd
670674
if opts.hold_after_ssh:
671-
if opts.cwd != 'current':
672-
raise ValueError("--hold_after_ssh can only be supplied if --cwd=current is also supplied")
675+
if opts.cwd not in ('current', 'last_reported', 'oldest'):
676+
raise ValueError("--hold-after-ssh can only be supplied if --cwd=current or similar is also supplied")
673677
kw['hold_after_ssh'] = True
674678

675679
if opts.location != 'default':

kitty/rc/launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Launch(RemoteCommand):
5757
watcher/list.str: list of paths to watcher files
5858
bias/float: The bias with which to create the new window in the current layout
5959
wait_for_child_to_exit/bool: Boolean indicating whether to wait and return child exit code
60-
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
60+
hold_after_ssh/bool: Boolean indicating whether to run a local shell after exiting the ssh session cloned via cwd=current or similar
6161
'''
6262

6363
short_desc = 'Run an arbitrary process in a new window/tab'

kitty/window.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,12 @@ def modify_argv_for_launch_with_cwd(self, argv: list[str], env: dict[str, str] |
167167
server_args = [] if run_shell else list(argv)
168168
from kittens.ssh.utils import set_cwd_in_cmdline, set_env_in_cmdline, set_server_args_in_cmdline
169169
if ssh_kitten_cmdline and ssh_kitten_cmdline[0] == 'kitten':
170-
if hold_after_ssh:
171-
argv[:] = [kitten_exe(), "run-shell", kitten_exe()] +ssh_kitten_cmdline[1:]
172-
else:
173-
argv[:] = [kitten_exe()]+ssh_kitten_cmdline[1:]
174-
else:
175-
argv[:] = ssh_kitten_cmdline
170+
ssh_kitten_cmdline[0] = kitten_exe()
171+
argv[:] = ssh_kitten_cmdline
176172
set_cwd_in_cmdline(reported_cwd, argv)
177173
set_server_args_in_cmdline(server_args, argv, allocate_tty=not run_shell)
174+
if hold_after_ssh:
175+
argv[:0] = [kitten_exe(), "run-shell"]
178176
if env is not None:
179177
# Assume env is coming from a local process so drop env
180178
# vars that can cause issues when set on the remote host
@@ -1784,6 +1782,8 @@ def ssh_kitten_cmdline(self) -> list[str]:
17841782
from kittens.ssh.utils import is_kitten_cmdline
17851783
for p in self.child.foreground_processes:
17861784
q = list(p['cmdline'] or ())
1785+
if len(q) > 3 and os.path.basename(q[0]) == 'kitten' and q[1] == 'run-shell':
1786+
q = q[2:] # --hold-after-ssh causes kitten run-shell wrapper to be added
17871787
if is_kitten_cmdline(q):
17881788
return q
17891789
return []

0 commit comments

Comments
 (0)