15 comments

[ 2.9 ms ] story [ 47.9 ms ] thread
I use entr for all my file-watching needs, if I need a roll-my-own solution. This article is a good introduction to the main ways to use it.

If you use Vim, however, its defaults can interfere with auto-build setups that depend on file watching: https://lee-phillips.org/badvim/

Another solution is just to use inotify-tools and inotify-watch and wrap that in a while true with your commands after. But I like this solution much more.
I use `entr` all the time for feedback on testing and development. Have you found a way to get it to handle "new" files. It is very good at watching a group of files, but my memory of it is that it barfs when you add/remove files?

> ls *.clj | entr -rcs './problem01.clj < input01.txt'

The problem is that ls only returns the list of files that existed at the time it was run...

There is an example of how to do that in the article, using `entr -d`.
Not a huge deal, but this "exits" when you have a change to a directory. So you end up having to put the whole thing in a while loop. But then you can't capture SIGINT and now you have to kill the process. So you need to write something that can capture that and conditionally break the loop if it is such...

entr is focused on doing what it does well, and I don't have a solution here. Just feels like there should be something to handle that use case.

Use -d and a while loop.

Keep in mind, this is a limitation of filesystem watchers, not entr specifically. It'd would have to do some juggling whenever a file was added.

I've also used Air[0] (and before that Gin) which says is for Go programs but lets you configure the commands and filters to work with any language/build.

[0] https://github.com/cosmtrek/air

(comment deleted)
This is a cool utility, but I feel that its existence is entirely predicated on not having a proper build system.

A proper build system should be able to be integrated with your editor or IDE, and whenever a save happens, a plugin for your editor/IDE, or a filesystem scan by the build system server, should activate a "quick build" using the list of changed files.

Of course, entr fills the niche where you want something to happen but don't want to go to the trouble of setting up a build system, so it had that going for it as well.

Disclaimer: I'm building such a build system. And now I wonder if I can design it such that it fulfills all of the roles entr does...

Disagree. I write build systems for fun and Entr is part of my daily toolkit anyway. You don't use a build system for everything, and filesystem watchers are glitchy at best. To create a watch on 30k files is a huge strain and is prone to fail.

Entr is great because it does one thing super duper well. Been using it for years almost daily and never have any issues with it.