Watch a dir and run a given command on changes.
I’ve found a few good use cases for the script so far. One is when your workflow is detached, i.e. for some reason you want to edit your files locally, but always have them syncronized on a remote server.
For these purposes my goto tool is the venerable rsync:
watch-and-run rsync -Pa --delete ~/some/dir remote.server:/remote/dirWhen developing it’s quite handy to run a kind of continous integration. While continous execution of unit tests inside an IDE is probably preferable, this provides a pretty decent alternative.
E.g. when I play around with developing Puppet modules, I might start the program with the following command:
BACKGROUND=1 DIR=~/projects/puppet watch-and-run make ubuntuIn the above we define that we want to
- start the process in the background,
- watch
~/projects/puppet - run
make ubuntuon change
For Puppet development this works nicely with docker-compose from the puppet-in-docker-examples repo.