Skip to content

Instantly share code, notes, and snippets.

@delphinus
Last active May 29, 2025 03:14
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 --format json | /usr/bin/ruby -r json -e 'puts JSON.parse($<.read).find{|x|x["pid"]=='$active_pid'}["focused_pane_id"]')
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
@delphinus
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment