Last active
August 29, 2015 14:06
-
-
Save ninjabiscuit/20c224243c2af4cf467e to your computer and use it in GitHub Desktop.
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 () { | |
# Note the date when the command started, in unix time. | |
CMD_START_DATE=$(date +%s) | |
# Store the command that we're running. | |
CMD_NAME=$1 | |
} | |
precmd () { | |
# Proceed only if we've ran a command in the current shell. | |
if ! [[ -z $CMD_START_DATE ]]; then | |
# Note current date in unix time | |
CMD_END_DATE=$(date +%s) | |
# Store the difference between the last command start date vs. current date. | |
CMD_ELAPSED_TIME=$(($CMD_END_DATE - $CMD_START_DATE)) | |
# Store an arbitrary threshold, in seconds. | |
CMD_NOTIFY_THRESHOLD=30 | |
if [[ $CMD_ELAPSED_TIME -gt $CMD_NOTIFY_THRESHOLD ]]; then | |
# play notification if the elapsed time (in seconds) is greater than threshold | |
afplay ~/.dotfiles/media/program-complete.wav -v 2 | |
# Send a notification | |
growlnotify -t "Program complete" -m "\"$CMD_NAME\" finished in $CMD_ELAPSED_TIME seconds." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generate an alert when long running tasks have finished executing in your terminal. This example uses a "program complete" sound bite from the LCARS computer on Star Trek TNG. It also uses Growlnotify to set a desktop notification. Props to Grrrlpower for the original version of this script.
Installation
.zshrc
file19
)21
to use your notification program of choice