-
-
Save hexode/11403574 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
| #!/bin/bash -e | |
| # | |
| # Author: Werner Beroux <werner@beroux.com> | |
| # Help? | |
| if [[ $# -eq 0 || $1 == --help || $1 == -h ]] | |
| then | |
| echo "inotifyexec version 1.0" | |
| echo "Requires inotify-tools." | |
| echo "" | |
| echo "Usage: inotifyexec <command> <inotifywait arguments...>" | |
| echo "Example: inotifyexec make -r . -qq -e modify,create,delete --exclude '*.swp'" | |
| echo "" | |
| echo "Once watch established, press Ctrl + C once to shutdown the watch cleanly." | |
| if [[ $# -eq 0 ]] | |
| then | |
| exit 1 | |
| else | |
| exit 0 | |
| fi | |
| fi | |
| exec_command=$1 | |
| shift | |
| inotifyargs=$* | |
| tmp_file=$(mktemp) | |
| # Listen to a single file changes, should be the temporary file changes. | |
| inotify_single_file() { | |
| # Ignore errors when executing the command. | |
| set +e | |
| while inotifywait -qq -e attrib $tmp_file | |
| do | |
| $exec_command | |
| done | |
| } | |
| # Fork a listener on the temporary file. | |
| touch $tmp_file | |
| inotify_single_file & | |
| # Keep listening to the desired directory: | |
| # Each change will touch the temporary file again. | |
| inotifywait --monitor $inotifyargs | while read dir ev file | |
| do | |
| touch $tmp_file | |
| done | |
| rm -f $tmp_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment