by inshadows · 6y ago · 0 comments
mkdir /tmp/project
cd /tmp/project
touch file{1,2}
ls | entr -d echo "a change"
Terminal 2: rm file2
Terminal 1: entr: cannot open 'file2': No child processes
Regarding `-d`:> Track the directories of regular files provided as input and exit if a new file is added. This option also enables directories to be specified explicitly. Files with names beginning with ‘.’ are ignored.
So first, it doesn't track NEW directories, and second, it exits if new file is added. Exactly how is this useful?
EDIT: All I want from filesystem watcher is to track files by pattern and just re-run the command, however complex that may be to implement via OS interfaces. When I'm working on a Python project that has packages (directories), I may also refactor (rename files), and this simplistic behavior does not catch that.
$ while true; do
> ls -d src/*.py | entr -d ./setup.py
> done
that way when a file/dir is added/removed it restarts Rebuild project if a source file is modified or added to the src/ directory:
$ while true; do ls src/*.rb | entr -d make; doneI've had good luck with modd: https://github.com/cortesi/modd/
I just tested exactly what you described, did not see any errors, and it ran my commands exactly the way I wanted.
I would also like to extol virtues of its sister project devd[0] from same author which makes web development palatable to me. It's a little websocker server that injects a tiny script into HTML to reload the page in browser once modd detects file change, rebuilds front-end and sends devd a SIGHUP.
I assume I'm misunderstanding something, so this is probably a naive question and maybe you can explain further, but if that is all you need why not just write it yourself? It sounds like an <1 hour project to write something cross-platform in Qt that monitors the filesystem recursively with QFileSystemWatcher https://doc.qt.io/qt-5/qfilesystemwatcher.html checks for the configured regexen and runs the configured command.
- Multiple files may change in quick succession, for example, if you hit “save all” in an editor. You might want to delay triggers to see if more events arrive.
- You will sometimes see incomplete / corrupted versions of files, because you ran a command while another program was writing the file. The other program probably should atomically rewrite the file, but you’re stuck fixing the problem. The user doesn’t want to see errors from this and you generally want to rerun the command.
- You need to execute commands in the correct order.
- A command may change state from being queued&ready to having outdated inputs.
If it’s just one command, sure, you could probably do it in an hour. But if there’s more than one command (usually the case!) then it gets far more complicated.
Just looking at the last time I implemented something like this--it was watchman + about 500 lines of code figuring out which actions to run and when. And that’s not even with any parallel execution.