emcrisostomo / fswatch

A cross-platform file change monitor with multiple backends: Apple OS X File System Events, *BSD kqueue, Solaris/Illumos File Events Notification, Linux inotify, Microsoft Windows and a stat()-based backend.
https://emcrisostomo.github.io/fswatch/
GNU General Public License v3.0
5.04k stars 328 forks source link

selective exclusion #273

Open mobileink opened 3 years ago

mobileink commented 3 years ago

Thanks for this great sw! I'm using libfswatch to create to tool and it's working great.

I'm looking for a good way to selectively exclude stuff. Currently I start by excluding everything (".*") and then adding includes for the directories I want to watch. The problem is that editors (well, at least emacs) like to create transient files that I do not need to watch. In particular, emacs creates and deletes lockfiles as you edit. For example, if you change foo.c, then emacs will create .#foo.c, which it will delete when you save your changes.

This results in three fs change events, for for .#foo.c create, one for foo.c update, one for .#foo.c removal.

Is there a simple way to exclude such files/events? I suppose I could write some kind of regex to handle it but that would presumably incur a performance hit. Maybe that's unavoidable. Obviously the workaround is to implement my own filtering logic on the events I receive, but it would be nice if libfswatch could handle this case.

Similar problem: suppose I want to watch a directory foodir (recursively), and somewhere below it there is a directory I want to ignore - e.g. a .git directory or some such. Any way I can tell libfswatch to handle this?

I guess I'm looking for filter conjunction, i.e. "include if regex1 AND NOT regex2".

Thanks,

Gregg

thoni56 commented 3 years ago

I totally agree!

I've been frustrated with this too, and it would really help to have an "exclusively match" option that only matches the patterns given.