Although popular compilers and bundlers like [`esbuild`](https://esbuild.github.io/) 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`](https://eradman.com/entrproject/entr.1.html).

For example (lifted from the documentation), you can replace a package like the popular npm package `nodemon` with this simple command.

```sh
$ 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](https://play.date/) 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.

```sh
$ 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:

```sh
$ 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`](https://github.com/cosmtrek/air) or [`bacon`](https://github.com/Canop/bacon), but for smaller scale projects it’s a wonderful tool.

### Notes

- Use `-rz` if you want to exit `entr` after a process has completed.

#### Tags

- [Command Line](/content/tags/command-line/index.html)
- [Tools](/content/tags/tools/index.html)
