Instantly share code, notes, and snippets.

@gonhainu /notify.zsh
Last active Dec 27, 2015

Embed
What would you like to do?
Mavericksでコマンド終了時に通知するスクリプト
## zsh integration: any command that takes longer than 3 seconds
## https://gist.github.com/syui/7112389/raw/growl.zsh
## http://qiita.com/kazuph/items/3bfdfce6b7d02b43bf4d
alias pong='perl -nle '\''print "display notification \"$_\" with title \"Terminal\""'\'' | osascript'
preexec() {
zsh_notify_cmd=$1
zsh_notify_time=`date +%s`
}
precmd() {
if (( $? == 0 )); then
# message
zsh_notify_status=done\!\!
else
zsh_notify_status=fail
fi
if [[ "${zsh_notify_cmd}" != "" ]]; then
# time
if (( `date +%s` - ${zsh_notify_time} > 3 )); then
echo ${zsh_notify_cmd} ${zsh_notify_status} | pong
fi
fi
zsh_notify_cmd=
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment