macosbashwatchfswatch

How to run fswatch to call a program with static arguments?


I used to use fswatch v0.0.2 like so (in this instance to run django test suit when a file changed)

$>fswatch . 'python manage.py test'

this works fine.

I wanted to exclude some files that were causing the test to run more than once per save (Sublime text was saving a .tmp file, and I suspect .pyc files were also causing this)

So I upgraded fswatch to enable the -e mode.

However the way fswatch has changed which is causing me troubles - it now accepts a pipe argument like so:

$>fswatch . | xargs -n1 program

I can't figure out how to pass in arguments to the program here. e.g. this does not work:

$>fswatch . | xargs -n1 python manage.py test

nor does this:

$>fswatch . | xargs -n1 'python manage.py test'

how can I do this without packaging up my command in a bash script?


Solution

  • fswatch documentation (either the Texinfo manual, or the wiki, or README) have examples of how this is done:

    $ fswatch [opts] -0 -o path ... | xargs -0 -n1 -I{} your full command goes here
    

    Pitfalls: