Last active
February 21, 2025 07:18
-
-
Save mataki/c42487e0fa7fba9375f97134c3caf76a to your computer and use it in GitHub Desktop.
Plays a sound to indicate completion or failure if a command takes a long time to execute on a Mac.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function save_command_start() { | |
COMMAND_START_TIME=$EPOCHSECONDS | |
} | |
function notify_command_end() { | |
local exit_status=$? | |
local duration=$(( EPOCHSECONDS - COMMAND_START_TIME )) | |
local last_command=$(fc -ln -1 | sed 's/^[ \t]*//') | |
if (( duration >= 30 )); then | |
if [ $exit_status -eq 0 ]; then | |
(afplay /System/Library/Sounds/Glass.aiff &> /dev/null &) | |
osascript -e "display notification \"Command: $last_command with $duration sec\" with title \"Last Command Executed\"" | |
else | |
(afplay /System/Library/Sounds/Basso.aiff &> /dev/null &) | |
osascript -e "display notification \"Command: $last_command with $duration sec\" with title \"Last Command Failed\"" | |
fi | |
fi | |
} | |
add-zsh-hook preexec save_command_start | |
add-zsh-hook precmd notify_command_end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add .zshrc