Last active
December 16, 2015 14:09
-
-
Save h3/5446756 to your computer and use it in GitHub Desktop.
Bootstrap's watch functionality, without the dependencies (and bugs) 1) Put it in your bootstrap folder witht he filename "watch.sh" 2) Then chmod a+x watch.sh 3) Use ./watch.sh to run.
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
#!/bin/bash | |
# Credits: | |
# v1 (original code): Ian Vaughan (http://stackoverflow.com/a/4960140/105905) | |
# v2 (Minor changes): Maxime Haineault (https://gist.github.com/h3/5446756) | |
sha=0 | |
previous_sha=0 | |
update_sha() | |
{ | |
sha=`ls -lR . | sha1sum` | |
} | |
build () { | |
echo | |
echo | |
echo "[preprocessor] monitoring filesystem... (Press enter to force a build/update)" | |
make | |
} | |
changed () { | |
echo "[preprocessor] file(s) changed, re-processing..." | |
previous_sha=$sha | |
build | |
} | |
compare () { | |
update_sha | |
if [[ $sha != $previous_sha ]] ; then changed; fi | |
} | |
run () { | |
while true; do | |
read -s -t 1 && ( | |
echo "[preprocessor] forced re-processing..." | |
build | |
) | |
compare | |
done | |
} | |
echo "[preprocessor] Watching for changes... (Press <enter> to force re-processing)" | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment