Created
April 4, 2013 03:25
-
-
Save notthetup/5307455 to your computer and use it in GitHub Desktop.
Oh my zsh custom script to growl on completion of all commands which take more than 10secs
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
preexec_functions+='save_preexec_time' | |
save_preexec_time() { | |
export PREEXEC_CMD="$(history $HISTCMD | tail -n 1 | sed 's/ *[0-9]* *//')" | |
export PREEXEC_TIME=$(date +'%s') | |
} | |
precmd_functions+='growl_about_long_running_commands' | |
growl_about_long_running_commands() { | |
exitstatus=$? | |
if [ $exitstatus -eq 0 ]; then | |
img="$HOME/.oh-my-zsh/custom/growl-pass.png" | |
else | |
img="$HOME/..oh-my-zsh/custom/growl-fail.png" | |
fi | |
stop=$(date +'%s') | |
start=${PREEXEC_TIME:-$stop} | |
let elapsed=$stop-$start | |
max=${PREEXEC_MAX:-10} | |
if [ $elapsed -gt $max ]; then | |
growlnotify -w -H localhost --image="$img" -n "LongRunningCommandGrowler" -m "Exited with status $exitstatus after $elapsed secs" ${PREEXEC_CMD:-Some command} | |
fi | |
PREEXEC_TIME= | |
PREEXEC_CMD= | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment