TIL: Auto-Running Commands on File Change With entr
Testing a script by running it manually after every edit is a waste of focus. entr watches files and runs a command when they change.
ls *.py | entr python test.py
Pipe the list of files to watch into entr. Every time a .py file changes, entr runs the test suite.
find . -name '*.js' | entr -c npm test
The -c flag clears the screen before each run. The output starts fresh every time.
ls server.js | entr -r node server.js
The -r flag sends a reload signal. If the command is a server, entr restarts it on file change. Like nodemon but for any command.
How do I install entr?
brew install entr
Does entr watch new files?
Only the files you pipe in initially. Add – to re-evaluate the command list, or use find with a cron-like approach.