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
+15
-2
@@ -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
|
||||
@@ -2076,7 +2089,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 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
|
||||
@@ -2098,7 +2111,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}')
|
||||
|
||||
|
||||
Reference in new issue
Block a user