Created
March 8, 2011 18:53
-
-
Save jamesmacaulay/860763 to your computer and use it in GitHub Desktop.
zsh hooks to growl completion of long-running commands
This file contains 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
# long-running command growler | |
# hooks for zsh, built on bash version at http://hints.macworld.com/article.php?story=20071009124425468 | |
preexec_functions+='save_preexec_time' | |
save_preexec_time() { | |
export PREEXEC_CMD="$(history $HISTCMD | 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/.zsh/images/pass.png" | |
else | |
img="$HOME/.zsh/images/fail.png" | |
fi | |
stop=$(date +'%s') | |
start=${PREEXEC_TIME:-$stop} | |
let elapsed=$stop-$start | |
max=${PREEXEC_MAX:-10} | |
if [ $elapsed -gt $max ]; then | |
growlnotify -H localhost --image="$img" -n "LongRunningCommandGrowler" -m "exited with status $exitstatus after $elapsed secs" ${PREEXEC_CMD:-Some command} | |
fi | |
PREEXEC_TIME= | |
PREEXEC_CMD= | |
} | |
adding this to oh-my-zsh would be awesome
You should be able to put this anywhere in the files that are loaded by zsh and have it picked up. I use a weird loading system that I picked up from someone before oh-my-zsh came around, so I don't really know how OMZ works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you install this, exactly?