Introducing entr

September 5, 2016
Tagged as: Fedora, entr, automation.

When writing code, my workflow is usually to make edits and re-run the test suite (that is, if there is one). This is actually a lot of work that I don't want to do.

Thankfully, it's quite easy to automate. All we need is a utility that would watch files for change and then run the tests.

On Linux, we can somewhat get by with inotifywait, but it is rather tedious. There must be a better way; and there actually is.

Well, the future is here and its name is entr. It runs arbitrary commands when files change. The list of files to monitor is provided on standard input.

It turned out that I most often want to watch all relevant files in current directory. Therefore, I created a small wrapper that will find all interesting files in current directory and pass them to entr. I call it guard.

#!/bin/sh
set -o pipefail
ag -g '' | entr "$@"

Using git ls-files would work almost as well as the silver searcher. Using find would work as well if you're inclined that way.

Go get it!

If you want to try it out and automate your workflow a bit, there is now a Fedora package, currently in waiting in Bodhi to be pushed stable (for F23, F24, F25 and EPEL 7). Feel free to get it from updates-testing repository.

$ sudo dnf install entr --enablerepo=updates-testing

Many thanks to Igor Gnatenko for review and packaging suggestions.