Skip to content

Instantly share code, notes, and snippets.

@h3

h3/watch.sh

Last active Dec 16, 2015
Embed
What would you like to do?
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.
#!/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