mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Support combined notify and bell on command finish
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user