4 ms·
Another wonderful tool is "entr". It just runs a program when files change. It's incredible. I use it 20-40 times an hour to do very fast Dev/DevOps developme
by john-tells-all 5y ago
Another wonderful tool is "entr". It just runs a program when files change.
It's incredible.
I use it 20-40 times an hour to do very fast Dev/DevOps development:
- "run Pytest when Python files change"
- "I forgot how to use ps, run my-ps.sh when it changes and show me the output"
- "rebuild all these Kubernetes resources when I edit the YAML files"
- "run fast lint, then unit test Python files, then invoke one and show me the results"
Link: https://jvns.ca/blog/2020/06/28/entr/ https://jvns.ca/blog/2020/06/28/entr/
- animal_spirits 5y agoWow! Thanks
- skrebbel 5y agoI use https://watchexec.github.io/ https://watchexec.github.io/ for this, which looks similar. Anyone who tried both and knows which one is better?
- benatkin 5y agoentr is written in C, watchexec is written in Rust. There's another one that I've used that is written in go: https://github.com/cespare/reflex https://github.com/cespare/reflex I am inclined to use watchexec next time I need one, because like go, I can read it more easily than c, but also because I looked at the web page and GitHub repo and it seems worth trying. For instance, it shows how to use it as a library instead of just as a command-line tool. https://watchexec.github.io/ https://watchexec.github.io/
- sinkensabe 5y agoI love watchexec! Really fast when doing TDD
- kzrdude 5y agowatchexec is a lot better at watching directories. entr deals with (existing files) best.
- userbinator 5y agoDo you have to be very careful when you save files if you're using that? I can imagine having it start a build that then spews tons of errors just because you saved a file that's only one of many changes you wanted to make, could become irritating more than anything else. Also, what happens when you change a file in the middle of a build that it started? I can see how it could be helpful, but with the way I write software, that scares me. I save habitually, and not only when I'm actually ready to build the result.
- laerus 5y agoentr comes with an option to interrupt the command in case of files change, by default it will wait for the command to finish.
- ducktective 5y agoYou're looking for a "hold-period" after a change in files are detected before triggering the action. This is called "debounce" in `watchexec` a similar program to `entr`
- morberg 5y agoI have the same workflow as you. It is not that hard to write ‘make test’ when you want to run your tests. I think there’s something I don’t understand about GP:s workflow and needs.
- ggreg84 5y agoI just use inotifywait for that. What does entr do differently? This will run a binary when any file on the directory tree changes: #!/usr/bin/env sh set -e while true; do inotifywait -e modify,create,delete,move -r $1 $2 done and then just call it: run_on_modify path/to/dir path/to/bin If someone thinks this is magic or wizardy, instead of teaching them that fire exists (entr), teach them how to make fire first (inotify, linux inodes, etc.). Knowing what kind of events inodes support and how to do something when they happen is pretty powerful. If you then want to use "entr" or similar instead of just calling inotifywait yourself, that's fair game. But TBH I have a hard time justifying a C or Rust program that's not going to be available / installed everywhere when a 3 LOC POSIX shell script can solve the same problem (and many many more).
- fragmede 5y agoinotifywait does a decent job of exposing the inotify primitive from the Linux kernel to userspace, but it's, well, primitive. Using that loop, if you change a file twice in quick succession, what happens? It'll trigger off the first change, but potentially ignore the second change if $2 takes longer to run than you can edit a file. You can improve the basic loop somewhat, but a more thoroughly written program (whatever the language) rather than a 3 LOC loop is going to have more features and be more ergonomic. In particular, to truly be useful, it should be able to kill the command and restart it every time the file is saved.