Skip to content

Add inotify support as an alternative to interval #1

@Gunni

Description

@Gunni

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

  1. watch recursively subscribes to inotify events for the specified directory (similar constraints to inotifywait)
  2. watch initially runs once
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions