Live data from Hacker News

Watchman: Execute a command when something changes

github.com

11–20 of 98 posts

Re: Watchman: Execute a command when something changes

#13
post #7
post #6

What does this add to inotifywait? That does exactly the same as this project, which uses inotifywait to reimplement inotifywait. For example: dnf install inotify-tools or apt-get install inotify-tools

ifnotifywait doesn't exist on macOS, so in addition to that not being an option on macos, this would be something you could write tools that a team who used multiple platforms, or a person with setups on multiple os's, could use. I suspect this might even be usable on windows. [edit: fswatch looks very promising, and may be a better choice than either ifnotifywait or watchman]

Discovered fswatch recently, it's proved very useful, my favorite use being replacing a few situations where I was using sshfs with fswatch+rsync: no network lag on save/load, can even work offline, but everything still makes its way to the network destination!

Re: Watchman: Execute a command when something changes

#15
post #3

Not to be confused with Facebook’s file watch daemon, also names watchman, which does the same sort of thing but is more complicated. There’s a bunch of tools that integrate Facebook’s watchman for more efficient change tracking. Advantages of Facebook’s watchman: 1. Implements efficient file system event watches on macOS and Windows 2. IPC/daemon system reduces resource use because overlapping watches/triggers don’t…

5. Windows is supported.

Re: Watchman: Execute a command when something changes

#16

This command seems like a no-brainer that should be in all OSes by default. It's mind-boggling that most systems don't have a standard tool for observing file changes. The only language I know of that has a platform-agnostic API for this is Factor.

The required kernel hooks exist in pretty much any common OS these days, it is a user-space tool that is sometimes missing.

It may not be installed by default, but inotifywait is available in common Linux distributions, usually in a package called something like ionotify-tools, and has been for over a decade-ana-half IIRC. It'll work under WSL on Windows too, though only for ext4 devices not bits of the Windows filesystem made available to Linux.

I can't speak to what other OSs include by default, but as every major OS has a different API for how to register a listener & how it gets messages no built-in tool is going to be cross-platform. There are third party tools which present more cross-platform consistency, most notably https://github.com/emcrisostomo/fswatch#readme (also available in common Linux distros, just an apt install away in Debian for instance).

Re: Watchman: Execute a command when something changes

#17
post #12

From my experience, these types of notification handlers are very fragile and tend to fail every so often. Do not use if your life depends on it.

From my experience, they break every time if you are making changes with tools that replace the file rather than change it in-place, like most text editors.

Re: Watchman: Execute a command when something changes

#18
post #17
post #12

From my experience, these types of notification handlers are very fragile and tend to fail every so often. Do not use if your life depends on it.

From my experience, they break every time if you are making changes with tools that replace the file rather than change it in-place, like most text editors.

In that case, you might want to monitor the directory too, not just the file. I believe this is even how it is supposed to work.

Re: Watchman: Execute a command when something changes

#19

I've seen about a dozen versions of this now. So my question is, who watches the watchmen?

If it’s running in a shell, it’d be the terminal session’s shell. If it’s running as a daemon, in a traditional Unix environment, it’d be the init process (pid 0).
Post reply on HN