Skip to content

Instantly share code, notes, and snippets.

@Arood
Created April 21, 2013 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arood/5430904 to your computer and use it in GitHub Desktop.
Save Arood/5430904 to your computer and use it in GitHub Desktop.
Watches for changes in JavaScript and Sass-folders
#!/bin/sh
JS_PATH="_js"
FINAL_JS="scripts.js"
SASS_PATH="_sass"
FINAL_CSS="."
sha=0
previous_sha=0
update_sha()
{
sha=`ls -lRT $JS_PATH $SASS_PATH | gsha1sum`
}
build () {
# Build/make commands here
rm $FINAL_JS
touch $FINAL_JS
cat $JS_PATH/*.js >> $FINAL_JS
echo " \033[0;32m$FINAL_JS\033[0m"
sass --update $SASS_PATH:$FINAL_CSS
}
changed () {
echo " ≫ Change detected. Rebuilding..."
build
previous_sha=$sha
}
compare () {
update_sha
if [[ $sha != $previous_sha ]] ; then changed; fi
}
run () {
update_sha
previous_sha=$sha
while true; do
compare
read -s -t 1 && (
echo " ≫ Forced rebuild..."
build
)
done
}
echo " ≫ Watching for changes. Press Ctrl-C to stop. Press enter to force rebuild."
run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment