From 5960314ffd1aaba19798f9b58ab3e09fe79df5f5 Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Sat, 31 May 2025 20:53:09 +1200 Subject: [PATCH] Support combined notify and bell on command finish --- kitty/options/definition.py | 4 ++++ kitty/options/utils.py | 4 ++-- kitty/window.py | 20 ++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 2017b0720..c930abf8f 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3482,6 +3482,10 @@ Second, the action to perform. The default is :code:`notify`. The possible value :code:`bell` Ring the terminal bell. +:code:`notify-bell` + Send a desktop notification and ring the terminal bell. + The arguments are the same as for `notify`. + :code:`command` Run a custom command. All subsequent arguments are the cmdline to run. diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 4b6fed3dc..890445a4e 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -803,10 +803,10 @@ def notify_on_cmd_finish(x: str) -> NotifyOnCmdFinish: cmdline: tuple[str, ...] = () clear_on = default_clear_on if len(parts) > 2: - if parts[2] not in ('notify', 'bell', 'command'): + if parts[2] not in ('notify', 'bell', 'notify-bell', 'command'): raise ValueError(f'Unknown notify_on_cmd_finish action: {parts[2]}') action = parts[2] - if action == 'notify': + if action.startswith('notify'): if len(parts) > 3: con: list[ClearOn] = [] for x in parts[3].split(): diff --git a/kitty/window.py b/kitty/window.py index 41ace3326..6d6256247 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -91,6 +91,7 @@ from .fast_data_types import ( wakeup_main_loop, ) from .keys import keyboard_mode_name, mod_mask +from .notifications import NotificationManager from .options.types import Options from .progress import Progress from .rgb import to_color @@ -1611,16 +1612,23 @@ class Window: cmd.only_when = OnlyWhen(when) if not nm.is_notification_allowed(cmd, self.id): return - if action == 'notify': - if self.last_cmd_end_notification is not None: + + def notify(window: Window, opts: Options, nm: NotificationManager) -> None: + if window.last_cmd_end_notification is not None: if 'next' in opts.notify_on_cmd_finish.clear_on: - nm.close_notification(self.last_cmd_end_notification[0]) - self.last_cmd_end_notification = None - notification_id = nm.notify_with_command(cmd, self.id) + nm.close_notification(window.last_cmd_end_notification[0]) + window.last_cmd_end_notification = None + notification_id = nm.notify_with_command(cmd, window.id) if notification_id is not None: - self.last_cmd_end_notification = notification_id, cmd.only_when + window.last_cmd_end_notification = notification_id, cmd.only_when + + if action == 'notify': + notify(self, opts, nm) elif action == 'bell': self.screen.bell() + elif action == 'notify-bell': + 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]) else: