Skip to content

Instantly share code, notes, and snippets.

@ichi
Created August 21, 2013 05:24
Show Gist options
  • Save ichi/6290619 to your computer and use it in GitHub Desktop.
Save ichi/6290619 to your computer and use it in GitHub Desktop.
autoload -U add-zsh-hook
# Growl notify long running command
__timetrack_threshold=20 # seconds
function __my_preexec_start_timetrack() {
local command=$1
export __timetrack_start=`date +%s`
export __timetrack_command="$command"
}
add-zsh-hook preexec __my_preexec_start_timetrack
function __my_preexec_end_timetrack() {
local exec_time
local command=$__timetrack_command
export __timetrack_end=`date +%s`
if ! which growlnotify >/dev/null 2>&1; then
return
fi
if [ -z "$__timetrack_start" ] || [ -z "$__timetrack_threshold" ]; then
return
fi
exec_time=$((__timetrack_end-__timetrack_start))
if [ -z "$command" ]; then
command="<UNKNOWN>"
fi
if [ "$exec_time" -ge "$__timetrack_threshold" ]; then
(
echo "Command finished!"
echo "Time: $exec_time seconds"
echo "COMMAND: $command"
) | growlnotify -n "ZSH timetracker" --appIcon Terminal
fi
unset __timetrack_start
unset __timetrack_command
}
add-zsh-hook precmd __my_preexec_end_timetrack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment