iWatch is a perl script that uses inotify to monitor files directories. It’s similar to the watch tool, which can do all sorts of stuff if the files or directories it’s watching are modified or affected in pretty much any way at all.

Install iWatch

apt-get install iwatch

I’ve got this 1 liner in a file to quickly watch my directory and execute a PHP unit test .

#!/bin/bash
iwatch -c "phpunit $1" -t '.*php$' -r -v -x ./.git -e modify .

I run this with a my argument (a unit test) and then sit there and code away. When I save, it detects the change and automatically runs my test. It’s pretty awesome.