Run commands on file change
Kovacsics Robert
There is an excellent tool called
entr
that can be used to run commands
on file change. I always forget what it’s called, so I’ve put this
tip here. (N.b.: it stands for Event Notify Test Runner.)
It can be used to automatically re-compile (and even restart servers) while you are editing the source files. A simple example is
git ls-files | entr make
Which works well for repos which only track source files. And depending
on what is in your makefile, it can for example build and flash the
embedded program onto the embedded target. (I tend to use CMake for
projects, with a simple makefile to avoid setting long makeprg/makecmd,
so I can just do :make<ret>
.)
On top of this, it also supports the -r
flag to reload a process
(e.g. a server/demo application), e.g.
git ls-files | entr go run ./cmd/server