Skip to content

Instantly share code, notes, and snippets.

@maleadt
Created October 21, 2014 09:51
Show Gist options
  • Save maleadt/81f87369aaf5e7d9d184 to your computer and use it in GitHub Desktop.
Save maleadt/81f87369aaf5e7d9d184 to your computer and use it in GitHub Desktop.
#!/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