The (command line) interface I have in mind is like so:
watching FILE+ do COMMAND [ARGS] (and COMMAND [ARGS])*
Where any occurrence of "{}
" in COMMAND
is replaced with the name of the file that changed. And note that "do
" and "and
" are keywords.
For example:
> watching foo.txt bar.txt do scp {} somewhere.com:. and echo moved {} to somewhere
Or:
> watching foo.c do gcc foo.c and ./a.out
I'm not wedded to that interface though. I'll add my script that does that as an answer and see if anyone has anything better or ways to improve it.
I just found this
every_change
script written in perl, that's very similar to the one I posted in my answer.So basically it does something every time a file changes.
Please check the
inotify
tools.You can use
entr
, e.g.Unfortunately you can't check which file has been changed, but using
rsync -u
will automatically skip files which haven't been changed.Here is the second example:
or simply use
make
, e.g.To watch the directory for changes, use
-d
parameter wrapped inside a shell loop, e.g.: