Merge pull request 'feat(notifications): notify when long commands finish, with duration and exit status' (#37) from feat/cmd-finish-notifications into main
Reviewed-on: #37
This commit was merged in pull request #37.
This commit is contained in:
commit
5cc8785eba
5 files changed
+42
-4
No files matched your search
@@ -222,6 +222,16 @@ Detailed list of changes
|
|||||||
0.50.1 [unreleased]
|
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
|
||||||
|
argument) now shows :code:`0` instead of an empty status.
|
||||||
|
|
||||||
- :kbd:`Ctrl+Shift+E` now opens the :doc:`file manager kitten
|
- :kbd:`Ctrl+Shift+E` now opens the :doc:`file manager kitten
|
||||||
<kittens/file-manager>` in a left dock by default, instead of requiring a
|
<kittens/file-manager>` in a left dock by default, instead of requiring a
|
||||||
manual mapping. This takes the key over from :ac:`open_url`; remap
|
manual mapping. This takes the key over from :ac:`open_url`; remap
|
||||||
|
|||||||
@@ -3355,11 +3355,14 @@ first valid match, in the order specified, is sourced.
|
|||||||
|
|
||||||
opt(
|
opt(
|
||||||
'notify_on_cmd_finish',
|
'notify_on_cmd_finish',
|
||||||
'never',
|
'unfocused',
|
||||||
option_type='notify_on_cmd_finish',
|
option_type='notify_on_cmd_finish',
|
||||||
long_text="""
|
long_text="""
|
||||||
Show a desktop notification when a long-running command finishes
|
Show a desktop notification when a long-running command finishes
|
||||||
(needs :opt:`shell_integration`).
|
(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:
|
The possible values are:
|
||||||
|
|
||||||
:code:`never`
|
:code:`never`
|
||||||
|
|||||||
Generated
+1
-1
@@ -640,7 +640,7 @@ class Options:
|
|||||||
mark3_foreground: Color = Color(0, 0, 0)
|
mark3_foreground: Color = Color(0, 0, 0)
|
||||||
momentum_scroll: float = 0.96
|
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)
|
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']
|
open_url_with: list[str] = ['default']
|
||||||
padding_fill_strategy: choices_for_padding_fill_strategy = 'background'
|
padding_fill_strategy: choices_for_padding_fill_strategy = 'background'
|
||||||
palette_generate: choices_for_palette_generate = 'fixed'
|
palette_generate: choices_for_palette_generate = 'fixed'
|
||||||
|
|||||||
+15
-2
@@ -283,6 +283,19 @@ def decode_cmdline(x: str) -> str:
|
|||||||
return ''
|
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):
|
class WindowDict(TypedDict):
|
||||||
id: int
|
id: int
|
||||||
is_focused: bool
|
is_focused: bool
|
||||||
@@ -2076,7 +2089,7 @@ class Window:
|
|||||||
cmd = nm.create_notification_cmd()
|
cmd = nm.create_notification_cmd()
|
||||||
cmd.title = 'kitty'
|
cmd.title = 'kitty'
|
||||||
s = self.last_cmd_cmdline.replace('\\\n', ' ')
|
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 in {format_cmd_duration(last_cmd_output_duration)} with status: {self.last_cmd_exit_status}.\nClick to focus.'
|
||||||
cmd.only_when = OnlyWhen(when)
|
cmd.only_when = OnlyWhen(when)
|
||||||
if not nm.is_notification_allowed(cmd, self.id):
|
if not nm.is_notification_allowed(cmd, self.id):
|
||||||
return
|
return
|
||||||
@@ -2098,7 +2111,7 @@ class Window:
|
|||||||
notify(self, opts, nm)
|
notify(self, opts, nm)
|
||||||
self.screen.bell()
|
self.screen.bell()
|
||||||
elif action == 'command':
|
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:
|
else:
|
||||||
raise ValueError(f'Unknown action in option `notify_on_cmd_finish`: {action}')
|
raise ValueError(f'Unknown action in option `notify_on_cmd_finish`: {action}')
|
||||||
|
|
||||||
|
|||||||
@@ -364,6 +364,18 @@ class TestNotifications(BaseTest):
|
|||||||
with tempfile.TemporaryDirectory() as tdir:
|
with tempfile.TemporaryDirectory() as tdir:
|
||||||
do_test(self, 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):
|
def test_freedesktop_close_before_created(self):
|
||||||
import kitty.fast_data_types as fdt
|
import kitty.fast_data_types as fdt
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user