Skip to content

Instantly share code, notes, and snippets.

@delphinus
Last active January 26, 2025 13:50
Show Gist options
  • Save delphinus/d1280fd9c9f32218f2c65477ec3640db to your computer and use it in GitHub Desktop.
Save delphinus/d1280fd9c9f32218f2c65477ec3640db to your computer and use it in GitHub Desktop.
Notify when slow commands finished in background
set -gx NOTIFY_ON_COMMAND_DURATION 5000
function fish_right_prompt
if test -n "$CMD_DURATION"; and test $CMD_DURATION -gt $NOTIFY_ON_COMMAND_DURATION
if type -q wezterm; and test -n "$WEZTERM_PANE"
set -l active_pid (osascript -e 'tell application "System Events" to get the unix id of first process whose frontmost is true')
set -l active_pane (wezterm cli list-clients | perl -anle 'print $F[$#F] if $F[2] == '$active_pid)
if test -n "$active_pane"; and test $WEZTERM_PANE -eq $active_pane
return
end
end
set -l duration (bc -S2 -e $CMD_DURATION/1000)
set -l msg (echo (history | head -1) returned $status after $duration s)
osascript -e 'display notification "'$msg'" with title "command completed"'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment