export NOTIFY_TIME=10 | |
function timer_start { | |
previous_command=$this_command | |
if [ "$BASH_COMMAND" != "timer_stop" ] | |
then | |
this_command=$BASH_COMMAND | |
fi | |
timer=${timer:-$SECONDS} | |
} | |
function timer_stop { | |
timer_show=$(($SECONDS - $timer)) | |
unset timer | |
# for commands that take > NOTIFY_TIME seconds, notify me | |
if [ $timer_show -gt $NOTIFY_TIME ]; then | |
if [ $? -eq 0 ]; then | |
status="Succeeded" | |
else | |
status="Failed" | |
fi | |
prompt_location="${PWD/#$HOME/\~} \$" | |
title="$prompt_location $(echo $previous_command | awk '{print $1}') $status" | |
terminal-notifier -title "$title" -message "$this_command" -sender "$prompt_location" | |
fi | |
} | |
trap 'timer_start' DEBUG | |
PROMPT_COMMAND=timer_stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment