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.
This one looks interesting: https://github.com/emcrisostomo/fswatch
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.
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
> 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
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)
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.