diff --git a/docs/changelog.rst b/docs/changelog.rst index 521a2757b..6f543d422 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -137,6 +137,8 @@ Detailed list of changes - Fix the :ref:`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] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/panel/main.py b/kittens/panel/main.py index 69ffc2ab8..e01584764 100644 --- a/kittens/panel/main.py +++ b/kittens/panel/main.py @@ -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: diff --git a/kitty_tests/child.py b/kitty_tests/child.py index 9a166772d..aead56061 100644 --- a/kitty_tests/child.py +++ b/kitty_tests/child.py @@ -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)