What does HackerNews think of 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.

Language: C++

#20 in C
#11 in C++
Well, I am not too lazy to search but I was interested in your experience, especially with reliability.

This one looks interesting: https://github.com/emcrisostomo/fswatch

I've been using fswatch to great effect. The big advantage is that it's truly cross-platform, falling back to polling if no fs notification system is available as long as stat(2) works.

Very composable as you just pipe its output to whatever you want (typically a while read do end), so exclusion is a awk/sed/perl/grep/rg away, and command can be as simple or complex as it needs to while the tool itself stays lean.

Cool features include -o to just be notified that something changed (e.g to fire up rsync), and ability to batch changes.

Also the command is a front end to libfswatch, so one can use that directly if shelling is to be foregone.

https://github.com/emcrisostomo/fswatch

> It watches source files, and regenerates the OpenSCAD files automatically

inotify() is awesome. Here's a library in python that does it.

https://michaelcho.me/article/using-pythons-watchdog-to-moni...

There's also inotifywatch on linux and fswatch on mac which makes it stupidly simple to do the same thing in a shell script. I'm sure there's alternatives for BSD Unix and Windows, but I care the least about those OS's.

https://github.com/emcrisostomo/fswatch https://linux.die.net/man/1/inotifywatch

Also interested in the response to the parent (loeg)

> facing many of the same difficulties that prompted the Windows team to just run Linux in a hypervisor

If by difficulties, you mean implementing system calls, this is being kept tabs on here: https://wiki.freebsd.org/Linuxulator

One that comes to mind is FreeBSD's kqueue, which opens a file descriptor for every file watched [1]

So inotify, inotify_add_watch, inotify_rm_watch isn't started. Lots of applications need watching of changes on directories. Even plain old FreeBSD gets messed since a large webpack project is going to chew up way too much.

If you're interested in this type of system call across operating systems check out https://github.com/emcrisostomo/fswatch

On WSL1/2:

Namely in WSL1, there were serious issues with package systems like npm, node_modules/ would have file descriptors get clogged, and it took a full system reboot to get WSL working again: https://github.com/microsoft/WSL/issues/1529. WSL2 Fixes it.

[1] https://emcrisostomo.github.io/fswatch/doc/1.8.0/fswatch.htm... See Freebsd -> kqueue -> Peculiarities

Using “watch” [1] to run your program is a bad idea. The watch command executes a program at regular intervals, by default it runs once every second.

What you should use instead is “inotifywait” [2] to execute your program(s) whenever there is a change. This way the program will run, for example, every time you save your changes. There are many utilities that make use of inotify (the library that powers inotifywait) some of them are fsnotify [3], fswatch [4] and watchexec [5].

[1] https://linux.die.net/man/1/watch

[2] https://linux.die.net/man/1/inotifywait

[3] https://github.com/fsnotify/fsnotify (written in Go — golang)

[4] https://github.com/emcrisostomo/fswatch (written in C++)

[5] https://github.com/watchexec/watchexec (written in Rust)

I didn't know about entr as well but I'm using fswatch which is largely similar and portable as well, supporting not only Linux and BSD but also non-WSL Windows and Solaris too, and leveraging the Filesystem Event API on macOS.

https://github.com/emcrisostomo/fswatch

Maybe look into the very unix-y fswatch, which is cross platform too.

https://github.com/emcrisostomo/fswatch

sure, FAT. OTOH some people think it's not a totally intractable problem

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.

http://emcrisostomo.github.io/fswatch/

https://github.com/emcrisostomo/fswatch

For people who are interested in doing these kind of things on other systems than Linux, check out fswatch, it's cross platform: https://github.com/emcrisostomo/fswatch