Created
October 21, 2014 09:51
-
-
Save maleadt/81f87369aaf5e7d9d184 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 | |
# Usage | |
function print_usage { | |
echo "Usage: $0 FILES... [-- MAKE OPTIONS...]" | |
} | |
# Process names options | |
MODE="files" | |
FILES=() | |
OPTIONS=() | |
while (( "$#" )); do | |
if [[ "$1" == "--" ]]; then | |
MODE="options" | |
elif [[ $MODE == "files" ]]; then | |
FILES+=("$1") | |
elif [[ $MODE == "options" ]]; then | |
OPTIONS+=("$1") | |
fi | |
shift | |
done | |
# Sanity checks | |
if [[ ${#FILES[@]} == 0 ]]; then | |
print_usage | |
exit 1 | |
fi | |
# Loop | |
# NOTE: double loop, because some editors delete+recreate (e.g. Sublime Text) | |
# rather than modify, causing the inotifywait loop to break | |
while true; do | |
set -x +e | |
make "${OPTIONS[@]}" | |
set +x -e | |
while inotifywait --event modify --quiet --recursive "${FILES[@]}"; do | |
set -x +e | |
make "${OPTIONS[@]}" | |
set +x -e | |
echo | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment