sharkdp / trigger

Run a user-defined command on file changes
MIT License
184 stars 9 forks source link

Add Mac support using fswatch #6

Closed ChrisPenner closed 4 years ago

ChrisPenner commented 4 years ago

This should do the trick. I've tested the Mac version, but unfortunately don't have a linux machine to test with so you may just want to double check that it still works 👍

sharkdp commented 4 years ago

Thank you for your contribution!

I can confirm that it works on Linux, but there seems to be a tiny change in behavior when the watched file/directory is removed.

Apparently, the "File '…' was deleted, waiting for it to reappear .." feature is currently broken on master (oops), but trigger exits cleanly (which is why I haven't noticed this, I had forgotten about the "waiting" feature).

With your PR however, the behavior is different:

If I run

trigger "echo event" /tmp/some-file

in one terminal and then rm /tmp/some-file in another terminal, I get the following output:

File '' was deleted, waiting for it to reappear ................................................

It doesn't ever come back because $cfile is not set correctly (but apparently that doesn't work on master either).

Unrelated from the issue above: why did you choose to use a bash array instead of bash functions (for example)? Just curious.

sharkdp commented 4 years ago

closing for now (cleaning up list of open PRs).