Created
July 13, 2012 16:23
-
-
Save vain/3105778 to your computer and use it in GitHub Desktop.
watch-and-notify
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
#!/bin/bash | |
# Requires inofity-tools. | |
# Get filename to watch. | |
if [[ -z "$1" ]] | |
then | |
cat << EOM | |
Usage: $(basename $0) <filename> [-c <context>] [args to 'notify-send' ...] | |
EOM | |
exit 1 | |
fi | |
fname="$1" | |
shift | |
# Lines of context? | |
context=10 | |
if [[ "$1" == "-c" ]] | |
then | |
context="$2" | |
shift | |
shift | |
fi | |
# Make sure it exists. | |
if [[ ! -f "$fname" ]] | |
then | |
touch "$fname" || exit 1 | |
fi | |
# Enter the watch loop. | |
while inotifywait -q -q -e close_write "$fname" | |
do | |
notify-send "$@" "$(tail -n "$context" "$fname" | tac)" | |
done | |
notify-send "$@" "Error: Can no longer watch \`$fname'!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment