Skip to content

Commit 5960314

Browse files
committed
Support combined notify and bell on command finish
1 parent e7514c6 commit 5960314

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

kitty/options/definition.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,6 +3482,10 @@
34823482
:code:`bell`
34833483
Ring the terminal bell.
34843484
3485+
:code:`notify-bell`
3486+
Send a desktop notification and ring the terminal bell.
3487+
The arguments are the same as for `notify`.
3488+
34853489
:code:`command`
34863490
Run a custom command. All subsequent arguments are the cmdline to run.
34873491

kitty/options/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,10 @@ def notify_on_cmd_finish(x: str) -> NotifyOnCmdFinish:
803803
cmdline: tuple[str, ...] = ()
804804
clear_on = default_clear_on
805805
if len(parts) > 2:
806-
if parts[2] not in ('notify', 'bell', 'command'):
806+
if parts[2] not in ('notify', 'bell', 'notify-bell', 'command'):
807807
raise ValueError(f'Unknown notify_on_cmd_finish action: {parts[2]}')
808808
action = parts[2]
809-
if action == 'notify':
809+
if action.startswith('notify'):
810810
if len(parts) > 3:
811811
con: list[ClearOn] = []
812812
for x in parts[3].split():

kitty/window.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
wakeup_main_loop,
9292
)
9393
from .keys import keyboard_mode_name, mod_mask
94+
from .notifications import NotificationManager
9495
from .options.types import Options
9596
from .progress import Progress
9697
from .rgb import to_color
@@ -1611,16 +1612,23 @@ def handle_cmd_end(self, exit_status: str = '') -> None:
16111612
cmd.only_when = OnlyWhen(when)
16121613
if not nm.is_notification_allowed(cmd, self.id):
16131614
return
1614-
if action == 'notify':
1615-
if self.last_cmd_end_notification is not None:
1615+
1616+
def notify(window: Window, opts: Options, nm: NotificationManager) -> None:
1617+
if window.last_cmd_end_notification is not None:
16161618
if 'next' in opts.notify_on_cmd_finish.clear_on:
1617-
nm.close_notification(self.last_cmd_end_notification[0])
1618-
self.last_cmd_end_notification = None
1619-
notification_id = nm.notify_with_command(cmd, self.id)
1619+
nm.close_notification(window.last_cmd_end_notification[0])
1620+
window.last_cmd_end_notification = None
1621+
notification_id = nm.notify_with_command(cmd, window.id)
16201622
if notification_id is not None:
1621-
self.last_cmd_end_notification = notification_id, cmd.only_when
1623+
window.last_cmd_end_notification = notification_id, cmd.only_when
1624+
1625+
if action == 'notify':
1626+
notify(self, opts, nm)
16221627
elif action == 'bell':
16231628
self.screen.bell()
1629+
elif action == 'notify-bell':
1630+
notify(self, opts, nm)
1631+
self.screen.bell()
16241632
elif action == 'command':
16251633
open_cmd([x.replace('%c', self.last_cmd_cmdline).replace('%s', exit_status) for x in notify_cmdline])
16261634
else:

0 commit comments

Comments
 (0)