Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created January 24, 2015 00:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baroquebobcat/8921fb917d9cdec93e32 to your computer and use it in GitHub Desktop.
Save baroquebobcat/8921fb917d9cdec93e32 to your computer and use it in GitHub Desktop.
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