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
4.96k stars 327 forks source link

Can't ignore files starting with '.#' #276

Open thoni56 opened 3 years ago

thoni56 commented 3 years ago

I'm looking to watch all C files but ignore Emacs lock files. E.g.

file.c # should match
.#file.c # should not match

I've tried various patterns, but as far as I could figure out by toying with https://www.regextester.com, the following should match

fswatch -e '.*' -i '^(?!\.#).*$' .

But I can't get that to work. I can't find a pointer to the exact regex specification that fswatch uses. (Actually I don't know if negative lookahead is considered "extended", but adding -E causes compilation of regex error.)

direvus commented 2 years ago

Try this:

fswatch -E -i '^[^.]+\.c$' -e '.*' .

The regular expression ^[^.]+\.c$ means "A string beginning with one or more characters that are not ., followed by a ., followed by c ending the string".

This should work fine for files that are in the top-level directory. If you're hoping to catch C files in subdirectories, you'll have to make the include pattern more clever to account for that.

Lookaheads and lookbehinds can be handy for some situations, but support for them varies considerably from one regex engine to another. It's better not to rely on them unless absolutely necessary.