From 3791cdc0248bb744dbe02e498b4b1176de7656d4 Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Wed, 11 Nov 2026 10:45:18 +0100 Subject: [PATCH 1/4] fix(notifications): report the parsed exit status of finished commands A shell that ends a command with a bare OSC 133;D leaves the raw status string empty, so the notification said "finished with status: ." and the command action got an empty %s. Use the status already parsed for the event instead. --- kitty/window.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kitty/window.py b/kitty/window.py index bf0c7a3..c871206 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -2074,7 +2074,7 @@ class Window: cmd = nm.create_notification_cmd() cmd.title = 'kitty' s = self.last_cmd_cmdline.replace('\\\n', ' ') - cmd.body = f'Command {s} finished with status: {exit_status}.\nClick to focus.' + cmd.body = f'Command {s} finished with status: {self.last_cmd_exit_status}.\nClick to focus.' cmd.only_when = OnlyWhen(when) if not nm.is_notification_allowed(cmd, self.id): return @@ -2096,7 +2096,7 @@ class Window: notify(self, opts, nm) self.screen.bell() elif action == 'command': - open_cmd([x.replace('%c', self.last_cmd_cmdline).replace('%s', exit_status) for x in notify_cmdline]) + open_cmd([x.replace('%c', self.last_cmd_cmdline).replace('%s', str(self.last_cmd_exit_status)) for x in notify_cmdline]) else: raise ValueError(f'Unknown action in option `notify_on_cmd_finish`: {action}') From 8708aa4101887d7bd44c3113a9aa9193ddf4d428 Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Wed, 11 Nov 2026 10:45:45 +0100 Subject: [PATCH 2/4] feat(notifications): show how long a command ran when it finishes The duration was measured to decide whether a command was long enough to warrant a notification, but it was never shown, so the notification could only say that the command had ended. Report it next to the exit status, formatted in milliseconds, seconds, minutes or hours depending on the length. --- kitty/window.py | 15 ++++++++++++++- kitty_tests/notifications.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/kitty/window.py b/kitty/window.py index c871206..8ded621 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -283,6 +283,19 @@ def decode_cmdline(x: str) -> str: return '' +def format_cmd_duration(seconds: float) -> str: + """Human readable duration for the notification sent when a command ends.""" + if seconds < 1: + return f'{seconds * 1000:.0f}ms' + if seconds < 60: + return f'{seconds:.1f}s' + minutes, secs = divmod(int(seconds), 60) + if minutes < 60: + return f'{minutes}m {secs}s' + hours, minutes = divmod(minutes, 60) + return f'{hours}h {minutes}m' + + class WindowDict(TypedDict): id: int is_focused: bool @@ -2074,7 +2087,7 @@ class Window: cmd = nm.create_notification_cmd() cmd.title = 'kitty' s = self.last_cmd_cmdline.replace('\\\n', ' ') - cmd.body = f'Command {s} finished with status: {self.last_cmd_exit_status}.\nClick to focus.' + cmd.body = f'Command {s} finished in {format_cmd_duration(last_cmd_output_duration)} with status: {self.last_cmd_exit_status}.\nClick to focus.' cmd.only_when = OnlyWhen(when) if not nm.is_notification_allowed(cmd, self.id): return diff --git a/kitty_tests/notifications.py b/kitty_tests/notifications.py index 2f90993..22048a7 100644 --- a/kitty_tests/notifications.py +++ b/kitty_tests/notifications.py @@ -364,6 +364,18 @@ class TestNotifications(BaseTest): with tempfile.TemporaryDirectory() as tdir: do_test(self, tdir) + def test_command_finish_duration_formatting(self): + from kitty.window import format_cmd_duration + + self.ae(format_cmd_duration(0), '0ms') + self.ae(format_cmd_duration(0.42), '420ms') + self.ae(format_cmd_duration(1.0), '1.0s') + self.ae(format_cmd_duration(59.94), '59.9s') + self.ae(format_cmd_duration(60), '1m 0s') + self.ae(format_cmd_duration(3599), '59m 59s') + self.ae(format_cmd_duration(3600), '1h 0m') + self.ae(format_cmd_duration(7325), '2h 2m') + def test_freedesktop_close_before_created(self): import kitty.fast_data_types as fdt From 8f8d2526abc182cfdcabf771f28ec09eb6ce56df Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Wed, 11 Nov 2026 10:45:45 +0100 Subject: [PATCH 3/4] docs: describe what the command finished notification reports Mention the command line, the duration and the exit status in the option documentation and record the new duration in the changelog. --- docs/changelog.rst | 5 +++++ kitty/options/definition.py | 1 + 2 files changed, 6 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9b5d2fe..b42d1a5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -222,6 +222,11 @@ Detailed list of changes 0.50.1 [unreleased] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- The :opt:`notify_on_cmd_finish` notification now reports how long the command + ran, next to the command line and the exit status it already showed. A shell + that ends a command without reporting a status (:code:`OSC 133;D` with no + argument) now shows :code:`0` instead of an empty status. + - :kbd:`Ctrl+Shift+E` now opens the :doc:`file manager kitten ` in a left dock by default, instead of requiring a manual mapping. This takes the key over from :ac:`open_url`; remap diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 78bbdcd..3467918 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3347,6 +3347,7 @@ opt( long_text=""" Show a desktop notification when a long-running command finishes (needs :opt:`shell_integration`). +The notification gives the command line, how long it ran and its exit status. The possible values are: :code:`never` From d6bdffca10f6eafc614c327aedb792a4d910e44d Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Wed, 11 Nov 2026 10:59:11 +0100 Subject: [PATCH 4/4] feat(options): notify when long commands finish by default The notification only happened if notify_on_cmd_finish was passed on the command line or written in kitty.conf, so a fresh build looked like it had no such feature at all. Long-running commands now notify by default once the window loses focus; the 5 second threshold keeps short commands silent. --- docs/changelog.rst | 5 +++++ kitty/options/definition.py | 4 +++- kitty/options/types.py | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index b42d1a5..6ffb633 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -222,6 +222,11 @@ Detailed list of changes 0.50.1 [unreleased] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- :opt:`notify_on_cmd_finish` is now enabled by default with the value + :code:`unfocused`: commands running longer than 5 seconds notify when the + window loses focus, without any configuration. Use :code:`never` to turn it + off. + - The :opt:`notify_on_cmd_finish` notification now reports how long the command ran, next to the command line and the exit status it already showed. A shell that ends a command without reporting a status (:code:`OSC 133;D` with no diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 3467918..417f60e 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3342,12 +3342,14 @@ first valid match, in the order specified, is sourced. opt( 'notify_on_cmd_finish', - 'never', + 'unfocused', option_type='notify_on_cmd_finish', long_text=""" Show a desktop notification when a long-running command finishes (needs :opt:`shell_integration`). The notification gives the command line, how long it ran and its exit status. +By default commands running longer than 5 seconds are reported when the window +loses focus, set the value to :code:`never` to disable this. The possible values are: :code:`never` diff --git a/kitty/options/types.py b/kitty/options/types.py index 0b19007..8bfc4d5 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -640,7 +640,7 @@ class Options: mark3_foreground: Color = Color(0, 0, 0) momentum_scroll: float = 0.96 mouse_hide_wait: MouseHideWait = MouseHideWait(hide_wait=0.0, show_wait=0.0, show_threshold=40, scroll_show=True) if is_macos else MouseHideWait(hide_wait=3.0, show_wait=0.0, show_threshold=40, scroll_show=True) - notify_on_cmd_finish: NotifyOnCmdFinish = NotifyOnCmdFinish(when='never', duration=5.0, action='notify', cmdline=(), clear_on=('focus', 'next')) + notify_on_cmd_finish: NotifyOnCmdFinish = NotifyOnCmdFinish(when='unfocused', duration=5.0, action='notify', cmdline=(), clear_on=('focus', 'next')) open_url_with: list[str] = ['default'] padding_fill_strategy: choices_for_padding_fill_strategy = 'background' palette_generate: choices_for_palette_generate = 'fixed'