I like to write about tools in my toolbelt I love, and entr is one of these preferred tools I enjoy using a lot.
Today I'm talking about entr – the Standalone File Watcher.
What's entr
?
entr ("Event Notify Test Runner"; GitHub), is a command-line tool written by Eric Radman that allows running arbitrary commands whenever files change.
It's not tied to any programming language, framework, platform, OS, etc. – it's a real standalone tool, pretty useful in a variety of scenarios.
Usage
First, use find
to craft a command that lists the files you're working with:
find . -name '*.md'
Then, just pipe it to entr
with a command to be run whenever files change:
find . -name '*.md' | entr echo "Markdown files changed!"
entr has some very interesting options, like the ability to clear the screen before running the given command (so you get a cleaner output). To get a full list of options, check its man
page with:
man entr
Continuously testing with entr
As you might have guessed, one of the main use cases for entr is to rerun tests whenever files change. I'm an Elixir engineer, and I use entr
to run mix test
continuously whenever I save an Elixir file.
This is the snippet I use to continuously test my Elixir library SwissSchema while I'm working on it:
find -E lib test -regex '.*exs?$' | entr -c mix test
A snippet I obviously can't recall from the top of my head every time I need to run it. Luckily, this project has a Makefile
with a task for it:
test.watch:
find -E lib test -regex .*exs?$ | entr -c mix test
💡 I wrote two articles here on DEV about Makefiles, one covering their overall utility and usage, and another with my Makefile setup for Elixir projects:
That's it. There's not much to learn, entr is really this awesome!
Top comments (0)