Watchexec vs. Entr — Which file-watcher should you use?
Summary recommendation
- Use watchexec if you want modern defaults, cross-platform support, built‑in ignore handling, and better process lifecycle management.
- Use entr if you prefer a tiny, battle‑tested Unix-only tool and you like composing explicit file lists with find/xargs.
Key differences
- Platform
- watchexec: cross‑platform (Linux, macOS FSEvents, Windows).
- entr: Unix-like only (POSIX environments).
- Defaults & ergonomics
- watchexec: recursively watches paths by default, respects .gitignore/.ignore, has sensible ignores for build artifacts.
- entr: expects an explicit list of files (commonly via find), so you compose precise inputs but must craft find patterns to avoid noise.
- Process management
- watchexec: can kill and restart long‑running processes cleanly (useful for dev servers).
- entr: simpler process handling; works fine for one‑off commands but less featureful for long‑running restarts.
- Event output / integration
- watchexec: supports structured event output (JSON) and environment variables for event info (improving integrations).
- entr: minimal output — you get a trigger and run a command; integrations rely on shell plumbing.
- Ignore patterns & noise
- watchexec: built‑in ignores and explicit ignore flags (e.g., -i) to avoid build loops.
- entr: you must exclude directories with your file‑listing command (find -prune, etc.).
- Performance & scale
- Both can handle typical projects; for very large trees, watchexec’s defaults may watch many files—use explicit watch (-w) or ignore (-i). entr’s explicit file lists can be more efficient if you carefully limit input.
- Installation & ecosystem
- watchexec: written in Rust, distributed via Homebrew, cargo, distro packages; active repo and features (event emission, JSON).
- entr: small C utility, often available in package managers, mature and simple.
Practical examples
- Quick cross‑platform run-on-save:
- watchexec: watchexec -e go ‘go test ./…’
- entr: find . -name ‘*.go’ | entr -r go test ./…
- Run a dev server that restarts on code change:
- watchexec: watchexec -r ‘your-server-command’(restarts cleanly)
- entr: find … | entr -c sh -c ‘kill $PID; your-server-command’ (you must manage PID)
Caveats / gotchas
- Avoid watching directories that contain build outputs (infinite loops). Use watchexec -i or entr with careful find exclusions.
- On very large codebases, prefer targeted watches (watchexec -w) or explicit file lists to reduce overhead.
- Some older watchexec versions had macOS issues; use a recent release.
When to choose which
- Choose watchexec if you want a convenient, cross‑platform, featureful watcher with smart defaults and better restart semantics.
- Choose entr if you need a minimal, portable Unix tool and you’re comfortable crafting file lists (or want the smallest dependency).
If you want, I can produce example commands for your project type (Node, Go, Rust, Python) using either tool.
Leave a Reply