Last active
September 9, 2020 17:44
-
-
Save igemnace/87508d54999bcd3f0cbbd0a9ce8612df to your computer and use it in GitHub Desktop.
Watch file modifications with inotifywait and run arbitrary commands on those files
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 | |
# Depends on inotifywait, from inotify-tools | |
# Usage: watchrun dir... -- command... | |
# e.g. watchrun src -- ctags -a | |
dirs=() | |
until [[ $1 == -- ]]; do | |
dirs+=("$1") | |
shift | |
done | |
shift | |
rest=("$@") | |
inotifywait -rme modify --format '%w%f' "${dirs[@]}" | while read -r filename; do | |
<&2 echo "Running for ${filename##*/}..." | |
"${rest[@]}" "$filename" | |
<&2 echo "Done." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment