Skip to content

Instantly share code, notes, and snippets.

@ygit
Created August 9, 2025 17:39
Show Gist options
  • Save ygit/e0867827dcefa8c8e1df48a8f94b624b to your computer and use it in GitHub Desktop.
Save ygit/e0867827dcefa8c8e1df48a8f94b624b to your computer and use it in GitHub Desktop.
# Bell + macOS notification when a terminal command takes >= 120s
# Bell + macOS notification when a command takes >= 120s
function __longrun_bell --on-event fish_postexec --argument-names cmdline
set -l threshold 120000 # ms
if set -q CMD_DURATION; and test "$CMD_DURATION" -ge $threshold
# 1) Sounds
printf '\a' # terminal BEL (enable Audible Bell in Warp)
command -q osascript; and osascript -e 'beep' >/dev/null 2>&1 # macOS alert sound
# 2) Make a friendly duration like "2m 3s"
set -l secs (math -s0 "$CMD_DURATION / 1000")
if test $secs -ge 3600
set -l h (math -s0 "$secs / 3600")
set -l m (math -s0 "($secs % 3600) / 60")
set -l s (math -s0 "$secs % 60")
set -l pretty "$h"h" $m"m" $s"s"
else if test $secs -ge 60
set -l m (math -s0 "$secs / 60")
set -l s (math -s0 "$secs % 60")
set -l pretty "$m"m" $s"s"
else
set -l pretty "$secs"s""
end
# 3) Desktop notification (osascript)
set -l shortcmd (string trim -- (string sub -l 80 -- $cmdline))
set -l msg "Done in $pretty — $shortcmd"
set -l msg_escaped (string replace -a '"' '\"' -- $msg)
osascript -e "display notification \"$msg_escaped\" with title \"Warp\" subtitle \"Long-running command\""
command -q terminal-notifier; and terminal-notifier -title "Warp" -subtitle "Long-running command" -message "$msg" >/dev/null 2>&1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment