CLI Tools: entr
Although popular compilers and bundlers like esbuild
commonly include --watch, -w
commands, not all tools offer a convenient file
system observer. Luckily, in true UNIX fashion there’s a great tool I recently
discovered that just watches for file changes and runs scripts:
entr
.
For example (lifted from the documentation), you can replace a package like the
popular npm package nodemon
with this simple command.
$ ls *.js | entr -r node app.js
The -r
flag tells entr
to reload the child process any time the output from
ls
changes, in this case node app.js
.
Examples
I’ve recently started playing around with the PlayDate SDK,
which compiles Lua code into a package that runs in the PlayDateSimulator app.
The pdc
utility doesn’t have a watch command, but with entr
it easily can.
$ ls *.lua | entr -r pdc Source/ MyGame.pdx
After a file save I just have to hop over to the simulator and hit CMD+R to reload, just like (old school) web development.
Go, Rust or Zig all come with testing libraries, but if you’re used to popular
JavaScript libraries like Jest or Vitest, having a --watch
flag is a nice
feature. With entr
it’s an easy add:
$ find *.go | entr -r go test
$ find src/*.rs | entr -r cargo test
Wrapping Up
I really enjoy little utilities like entr
. It isn’t a drop-in replacement for
great, fully featured libraries like air
or
bacon
, but for smaller scale projects it’s a
wonderful tool.
Notes
- Use
-rz
if you want to exitentr
after a process has completed.