ファイルの更新を監視してコマンドを実行するワンライナー

phpunit を実行させるために Grunt を使いましたが・・・

まあファイルの更新を監視して phpunit(に限らず任意のコマンド)を実行するだけならワンライナーです。

$ inotifywait -e create,delete,modify,move -mr src tests|while read;do while read -t 0.3;do :;done;phpunit -c tests;done

バラすとこうなります。

$ inotifywait -e create,delete,modify,move -m -r src/ tests/ |
while read; do
    while read -t 0.3; do
        :
    done
    phpunit -c tests/
done

ただし Linux に限る。


inotifywait が必要なので RHEL/CentOS の場合は epel から inotify-tools をインストールしておいてください。

$ yum localinstall -y http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ yum install --enablerepo=epel inotify-tools

そういえばシェルスクリプトっぽくしたものがあったので Gist に置いときます。

gist7786721