Last active
December 30, 2018 11:44
-
-
Save wookietreiber/6145723 to your computer and use it in GitHub Desktop.
do something when a file is modified, e.g. convert markdown to pdf: $ inotify-action foo.md pandoc -o foo.pdf foo.md
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
#!/usr/bin/env bash | |
declare -a watches | |
while [[ -n $1 && $1 != "--" ]] | |
do | |
watches+=("$1") | |
shift | |
done | |
# check if we have something to watch | |
if [[ ${#watches[@]} -eq 0 ]] | |
then | |
echo "usage: $(basename "$0") FILE... -- command" >&2 | |
exit 1 | |
fi | |
# shift away the double dashes | |
shift | |
# check if we have a command | |
if [[ -z $1 ]] | |
then | |
echo "usage: $(basename "$0") FILE... -- command" >&2 | |
exit 1 | |
fi | |
# start command once | |
"$@" | |
# now wait for changes and then start command | |
while inotifywait -qr -e modify "${watches[@]}" &> /dev/null | |
do | |
"$@" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment