Hacker News new | ask | show | jobs
by ggreg84 1549 days ago
I just use inotifywait for that. What does entr do differently?

This will run a binary when any file on the directory tree changes:

    #!/usr/bin/env sh
    set -e
    while true; do
        inotifywait -e modify,create,delete,move -r $1 $2
    done
and then just call it: run_on_modify path/to/dir path/to/bin

If someone thinks this is magic or wizardy, instead of teaching them that fire exists (entr), teach them how to make fire first (inotify, linux inodes, etc.). Knowing what kind of events inodes support and how to do something when they happen is pretty powerful.

If you then want to use "entr" or similar instead of just calling inotifywait yourself, that's fair game. But TBH I have a hard time justifying a C or Rust program that's not going to be available / installed everywhere when a 3 LOC POSIX shell script can solve the same problem (and many many more).

1 comments

inotifywait does a decent job of exposing the inotify primitive from the Linux kernel to userspace, but it's, well, primitive. Using that loop, if you change a file twice in quick succession, what happens? It'll trigger off the first change, but potentially ignore the second change if $2 takes longer to run than you can edit a file.

You can improve the basic loop somewhat, but a more thoroughly written program (whatever the language) rather than a 3 LOC loop is going to have more features and be more ergonomic. In particular, to truly be useful, it should be able to kill the command and restart it every time the file is saved.