Running command on file changes
Posted on Jan. 20, 2025 by Ben Dickson.
There is a lot of tools to run some command when a file is edited, with various levels of completeness and complication
watchexec seems like a good balance.
For example, to execute cargo run when things change (restart the process if it's still running):
watchexec -r -- cargo run
It also works with shell commands like
watchexec -r -- 'cargo run && python -m http.server --directory _generated'
Found it from this article, which also describes a more elabourate setup which handles socket connections better.