Skip to content

Instantly share code, notes, and snippets.

@derekwyatt
Created September 1, 2012 15:32
Show Gist options
  • Save derekwyatt/3577440 to your computer and use it in GitHub Desktop.
Save derekwyatt/3577440 to your computer and use it in GitHub Desktop.
Executes an arbitrary command when files change.
#!/bin/bash
command="$1"
shift
fileSpec="$@"
sentinel=/tmp/t.$$
touch -t197001010000 $sentinel
while :
do
files=$(find . -newer $sentinel -a '(' $fileSpec ')')
if [ $? != 0 ]; then
exit 1;
fi
if [ "$files" != "" ]; then
$command
touch $sentinel
fi
sleep 0.1
done
execOnChange.sh "mvn test" -name \*.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment