diff --git a/docs/changelog.rst b/docs/changelog.rst index 33459100f..efdc02a88 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -235,6 +235,10 @@ Detailed list of changes scaled text and emoji sequences being split into multiple cells when wrapped onto the next line (:pull:`10767`) +- zsh integration: Fix a "maximum nested function level reached" error at + every prompt after interrupting a command run at shell startup, for example + via a session file (:iss:`10768`) + - Fix changing text marker colors at runtime, for example with :code:`kitten @ set-colors` or automatic dark/light theme switching, applying the colors of each marker to the next one, with changes to ``mark3`` having diff --git a/kitty_tests/shell_integration.py b/kitty_tests/shell_integration.py index 5d88b44c1..c539111f6 100644 --- a/kitty_tests/shell_integration.py +++ b/kitty_tests/shell_integration.py @@ -374,6 +374,18 @@ RPS1="{rps1}" pty.wait_till(lambda: 'XXX' in pty.screen_contents()) self.assertIn('pre-start', pty.screen_contents()) self.assertTrue(pty.screen_contents().startswith('pre-start')) + # Interrupting the startup command must not leave integration half + # initialized. The marker is printed by the child itself so that we + # know it is the foreground job when we send SIGINT. + with self.run_shell(rc='PS1=XXX', extra_env={'KITTY_SI_RUN_COMMAND_AT_STARTUP': "sh -c 'echo pre-start; exec sleep 100'"}) as pty: + pty.wait_till(lambda: 'pre-start' in pty.screen_contents()) + pty.write_to_child('\x03') + pty.wait_till(lambda: 'XXX' in pty.screen_contents()) + pty.send_cmd_to_child('echo ok1') + pty.wait_till(lambda: '\nok1\n' in pty.screen_contents()) + pty.send_cmd_to_child('echo ok2') + pty.wait_till(lambda: '\nok2\n' in pty.screen_contents()) + self.assertNotIn('FUNCNEST', pty.screen_contents()) @unittest.skipUnless(shutil.which('fish'), 'fish not installed') def test_fish_integration(self): diff --git a/shell-integration/zsh/kitty-integration b/shell-integration/zsh/kitty-integration index 36473e21f..40ef8bf87 100644 --- a/shell-integration/zsh/kitty-integration +++ b/shell-integration/zsh/kitty-integration @@ -353,7 +353,15 @@ _ksi_deferred_init() { # run startup command if [[ -n "$krcs" ]]; then builtin print -nu "$_ksi_fd" -f '\e]2;%s\e\\' -- "${(V)krcs}" - builtin eval "$krcs" + # If the command is interrupted with Ctrl-C, zsh aborts the rest of + # this function, leaving it in precmd_functions so it runs again on the + # next prompt and wraps our zle widgets around themselves, causing + # infinite recursion. Clear the interrupt so initialization completes. + { + builtin eval "$krcs" + } always { + TRY_BLOCK_INTERRUPT=0 + } fi if (( $+functions[_ksi_preexec] )); then