Use case
I often want to run a command only when something in a directory changes. Tools like inotifywait can do this, but the syntax is hard to remember, while watch already provides the screen-refresh UX I prefer. Adding an inotify-triggered mode to watch would streamline this workflow.
Proposed CLI
watch --inotify=<path> <command>
Argument Explanation
--inotify takes an argument full or relative <path> argument which must exist, and be a
- a filename, in which case,
watch adds an inotify watch on that single file
- add a warning to the manual that many editors replace the file instead of modifying it in place, making this method unusable
- a directory, in which case,
watch recursively adds a inotify watch on the entire directory tree (limited by fs.inotify.max_user_watches)
- may be specified multiple times to add more paths
--inotify-events=<event1>[,<eventN>]
- See list of event types in here
- Defaults to:
CLOSE_WRITE
Expected Behavior
watch recursively subscribes to inotify events for the specified directory (similar constraints to inotifywait)
watch initially runs once
- On relevant events (e.g.,
CLOSE_WRITE), watch clears the screen and re-runs the <command>
- Overridable with
--inotify-events=<event1>[,<eventN>]
Why This Helps
inotifywait syntax is non‑intuitive and I always have to look it up
- I already use
watch constantly; an event-driven mode feels like a natural extension
- Polling intervals aren't “smart” — events are
Bonus Suggestions
- A
--tail option to always keep the bottom of the command output visible
- Optional support for mouse scrolling (similar to vim in terminal environments)
Prior Art
While writing this issue, I stumbled on similar functionality in other tools.
Use case
I often want to run a command only when something in a directory changes. Tools like
inotifywaitcan do this, but the syntax is hard to remember, whilewatchalready provides the screen-refresh UX I prefer. Adding aninotify-triggered mode towatchwould streamline this workflow.Proposed CLI
Argument Explanation
--inotifytakes an argument full or relative<path>argument which must exist, and be awatchadds aninotifywatch on that single filewatchrecursively adds ainotifywatch on the entire directory tree (limited byfs.inotify.max_user_watches)--inotify-events=<event1>[,<eventN>]CLOSE_WRITEExpected Behavior
watchrecursively subscribes toinotifyevents for the specified directory (similar constraints toinotifywait)watchinitially runs onceCLOSE_WRITE),watchclears the screen and re-runs the<command>--inotify-events=<event1>[,<eventN>]Why This Helps
inotifywaitsyntax is non‑intuitive and I always have to look it upwatchconstantly; an event-driven mode feels like a natural extensionBonus Suggestions
--tailoption to always keep the bottom of the command output visiblePrior Art
While writing this issue, I stumbled on similar functionality in other tools.