It’s a fairly common pattern that you have some code that you’re repeatedly running. Perhaps you’re fixing a failing test, and you just have to keep running it every time you make a fix.
Enter entr
. This handy little tool reruns a particular command whenever changes are detected in a particular set of files.
Let’s take the example I mentioned above: you have a failing test that you’re debugging and you need to have it run every time you save a change to the file. Assuming your source code is stored in src
and you’re using pytest
, then you could use something like the following:
ls src/*.py | entr -c pytest test.py::test_some_feature
So now, any time you change any Python file inside the src
folder, it’ll rerun your test. The -c
flag will clear the terminal every time the test runs.
[Many thanks to calmcode for continuing to make these really useful videos.]