This is like an Autotest script but you have to tell it what files to watch, also can be used for anything that waits for when a file changes (assumes the file is called mywatch, the echo sh … line is all one line):
#! /bin/sh
if [ “$#” -eq 0 ]
then echo Usage: $0 command files
echo runs the command every time the files have changed
echo put the command into quotes
echo example:
echo sh ./mywatch.sh ‘”ruby script/spec spec/models/article_spec.rb —format specdoc”’ spec/models/article_spec.rb app/models/article.rb
echo ^C quits
else
command=$1
shift
touch /tmp/old_ls.$$
while :
do
ls -l $* > /tmp/new_ls.$$
diff -q /tmp/new_ls.$$ /tmp/old_ls.$$ || eval $command
mv /tmp/new_ls.$$ /tmp/old_ls.$$
sleep 3
done
fi
Footnote:
Found a Ruby way of doing this http://nubyonrails.com/articles/automation-with-rstakeout also added some code that will use the windows Snarl, rather than the Mac growl to send messages and a one line script for people who are lazy enough to not want to type long commands, see this.