- Add this to your .rc file
preexec () {
(( $#_elapsed > 1000 )) && set -A _elapsed $_elapsed[-1000,-1]
typeset -ig _start=SECONDS
}
# Notify about long running commands
function precmd() {
_result=$?
# Update elapsed time
set -A _elapsed $_elapsed $(( SECONDS-_start ))
if (( ( $_elapsed[-1] > 20 ) )); then
if (( ( $_result > 0 ) )); then
terminal-notifier -message "Command failed: $(fc -l -n -1)" -title $(realpath --relative-base=$HOME/dd -s $(pwd)) -ignoreDnD
say "command failed"
else
terminal-notifier -message "Command completed" -title $(realpath --relative-base=$HOME/dd -s $(pwd)) -ignoreDnD
say "command completed"
fi
fi
}
- Install terminal-notifier
- Allow alerts from your terminal program (iTerm in my case) and terminal-notifier
