Skip to content

Instantly share code, notes, and snippets.

@perfectfoolish
Forked from derekwyatt/execOnChange.sh
Created December 1, 2012 13:02
Show Gist options
  • Save perfectfoolish/4182169 to your computer and use it in GitHub Desktop.
Save perfectfoolish/4182169 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