Created
August 21, 2013 05:24
-
-
Save ichi/6290619 to your computer and use it in GitHub Desktop.
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
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