panel kitten: Use the invocation cwd and a cleaned env for single instance commands
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run

A new panel created via single instance now runs in the working
directory of the invocation, rather than that of the first instance, as
commands run in existing panels and other single instance commands
already do. The environment of the invocation is cleaned up with
process_env() as for other single instance commands, so that variables
such as XDG_ACTIVATION_TOKEN and VTE_VERSION are not passed to the
commands.
This commit is contained in:
Kovid Goyal 2026-11-19 19:56:17 +05:30
parent d5be3448a6
commit 0b56ffd328
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 6 deletions

View file

@ -137,6 +137,8 @@ Detailed list of changes
- Fix the :ref:`launch wrapper <launch_wrapper>` not being used for programs run in an already running panel or quick access terminal in single instance mode (:pull:`10900`)
- panel kitten: In single instance mode, run the command in a new panel in the working directory it was invoked from and do not pass internal environment variables such as :code:`XDG_ACTIVATION_TOKEN` to commands run in panels, as for other single instance commands
0.51.0 [2026-11-18]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -170,11 +170,14 @@ def have_config_files_been_updated(config_files: Iterable[str]) -> bool:
def window_for_command(cmd: list[str], environ: Mapping[str, str], launch_type: str, cwd: str = '') -> 'SpecialWindowInstance':
# The command is requested by the user via a separate invocation of the
# panel kitten, so it is passed to the launch wrapper, without a source
# window, since it is not run from any window in this kitty instance.
# window, since it is not run from any window in this kitty instance. The
# environment and working directory are those of the invocation, with the
# environment cleaned up as for other single instance commands.
from kitty.child import process_env
from kitty.launch_wrapper import LaunchRequest
from kitty.tabs import SpecialWindow
return SpecialWindow(cmd=cmd, env=dict(environ), cwd=cwd or None, hold=args.hold, launch_request=LaunchRequest(launch_type))
return SpecialWindow(cmd=cmd, env=process_env(environ), cwd=cwd or None, hold=args.hold, launch_request=LaunchRequest(launch_type))
def run_in_existing_panel(boss: BossType, cmd: list[str], environ: Mapping[str, str], cwd: str) -> None:
@ -224,7 +227,7 @@ def handle_single_instance_command(
# Without a command run the shell, as a panel started without single
# instance does. Not kitty's run-shell kitten, so that the launch wrapper
# sees the actual shell.
tm.new_tab(window_for_command(items or resolved_shell(get_options()), environ, 'os-window'))
tm.new_tab(window_for_command(items or resolved_shell(get_options()), environ, 'os-window', cwd))
def main(sys_args: list[str]) -> None:

View file

@ -636,14 +636,14 @@ read -r _
patch.object(panel, 'set_layer_shell_config'),
patch.object(panel, 'toggle_os_window_visibility'),
):
panel.handle_single_instance_command(boss, sys_args, {'X': 'y'}, cwd=cwd)
panel.handle_single_instance_command(boss, sys_args, {'X': 'y', 'XDG_ACTIVATION_TOKEN': 't', 'VTE_VERSION': '1'}, cwd=cwd)
launch = tab.new_special_window if launch_type == 'window' else tm.new_tab
launch.assert_called_once()
sw = launch.call_args.args[0]
# Cleaned up as for other single instance commands
self.ae(sw.env, {'X': 'y'})
self.ae(sw.hold, hold)
# A new panel is not given the cwd of the invocation
self.ae(sw.cwd, None if launch_type == 'os-window' else cwd)
self.ae(sw.cwd, cwd)
wrapper = self._recording(['/bin/wrapper'])
_, _, argv = self._fork(argv=sw.cmd, launch_request=sw.launch_request, hold=sw.hold, cwd=sw.cwd or '/', user_func=wrapper)
self.ae(argv[-3:], ('/bin/wrapper', *cmd))
@ -665,6 +665,8 @@ read -r _
shell = resolved_shell(get_options())
self.ae(sw.cmd, shell)
self.ae(sw.launch_request.launch_type, 'os-window')
# No cwd sent by the client, so the default is used
self.assertIsNone(sw.cwd)
self._fork(argv=sw.cmd, launch_request=sw.launch_request, user_func=self._recording(None))
self.ae(self.contexts[-1].argv, tuple(shell))
self.assertTrue(self.contexts[-1].is_default_shell)