Created
August 28, 2015 08:25
-
-
Save drobune/7dbbb8abbca306269148 to your computer and use it in GitHub Desktop.
zsh notify
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
#copy from https://www.reddit.com/r/linux/comments/1pooe6/zsh_tip_notify_after_long_processes/ | |
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=60 | |
if [[ $CMD_ELAPSED_TIME -gt $CMD_NOTIFY_THRESHOLD ]]; then | |
# Beep or visual bell if the elapsed time (in seconds) is greater than threshold | |
print -n '\a' | |
# Send a notification | |
notify-send 'Job finished' "The job \"$CMD_NAME\" has finished." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment