talira

Run arbitrary commands when files change

open sourceISCself-hostablefree

entr (Event Notify Test Runner) runs a command whenever any of a list of files changes, using kqueue or inotify instead of polling. You pipe it a list of files from ls, find, ag or ack, so it composes with ordinary Unix tools. It can clear the screen, run through a shell, restart a long-running process such as a server on each change, react to new files in a directory, and pass the changed file name to the command. It is written by Eric Radman and runs on BSD, macOS and Linux.

Ways to install

Problems it solves

  • rerun my tests every time I save a source file without a heavyweight watcher
  • restart my dev server automatically when the code changes
  • rebuild the project when any file in a list changes, using plain Unix pipes
  • re-run a SQL script against the database each time I edit it
  • watch a directory and react when a new file is added
  • clear the terminal and show fresh output whenever my files change

Features

  • uses kqueue(2) or inotify(7), no polling
  • reads the list of files to watch from standard input
  • -r restarts a long-running process on change
  • -d reacts to new files in watched directories
  • -c clears the screen, -s runs the command through a shell
  • /_ placeholder for the changed file
  • custom status messages with awk status filters
  • workaround for incomplete inotify on WSL and Docker for Mac

Limitations

  • Can't restart an interactive program: the -r flag can't be used with a task that reads from standard input3

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what entr does.

  1. watchexec Executes commands in response to file modifications
  2. bacon Background code checker
  3. Air Live reload for Go apps

Compare entr with the top 3