Created
January 3, 2012 18:53
-
-
Save IanVaughan/1556291 to your computer and use it in GitHub Desktop.
Bash script that monitors a directory of source files for changes, then does something (like build) if changed.
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 | |
# Bash script that monitors a directory of source files for changes, then does something (like build) if changed. | |
# It does this via creating a SHA of the ls tree of the folder in question, and if changed, triggers the action. | |
# The "action" is just the variable $command, normally make. | |
# Usage : | |
# ./monitor.sh | |
# Then save a file, and it gets built! Magic! | |
command="make" | |
params="" | |
if [ $1 ]; then | |
echo "--> Monitor: Passing parameters :" $* | |
params="$*" | |
fi | |
sha=0 | |
previous_sha=0 | |
update_sha() | |
{ | |
sha=`ls -lR . | egrep '\.cpp|\.h|\.spt' | sha1sum` | |
} | |
build () { | |
${command} ${params} | |
echo | |
echo "--> Monitor: Monitoring filesystem... (Press enter to force a build/update)" | |
} | |
changed () { | |
echo "--> Monitor: Files changed, Building..." | |
build | |
previous_sha=$sha | |
} | |
compare () { | |
update_sha | |
if [[ $sha != $previous_sha ]] ; then changed; fi | |
} | |
run () { | |
while true; do | |
compare | |
read -s -t 1 && ( | |
echo "--> Monitor: Forced Update..." | |
build | |
) | |
done | |
} | |
echo "--> Monitor: Init..." | |
echo "--> Monitor: Monitoring filesystem... (Press enter to force a build/update)" | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bash script that monitors a directory of source files for changes, then does something (like build) if changed.
It does this via creating a SHA of the ls tree of the folder in question, and if changed, triggers the action.
The "action" is just the variable $command, normally make.
Usage :
./monitor.sh Then save a file, and it gets built! Magic!