entr
Run arbitrary commands when files change
Date: 07 November 2021
Long ago, I came across a tool called entr, and it's a pretty cool program actually.
What it does is really simple, but yet powerful, it let you run any arbitrary set of commands when a specific files changes.
The entr's website has a great explanation for it with a bunch of great examples to start with.
But long story short, you pass a set of files (using regex for example) to the command through stdin
, and then make it run
a script or a command whenever one of these file changes.
For example, here I make it monitor any markdown
files in my current directory, and execute a script that commit and pushes the changes
i made automatically.
find -iname "*.md" | entr commit-and-push.sh
1 My use case
I can think of numerous use cases and scenarios in which this utility may be quite useful, but for the time being, I'm integrating it into my blog writing workflow.
org mode is a markdown language and a major mode for Emacs
Before i publish any blog online, I use a small local web server to see the output result locally . Of course I use Emacs and org mode to create my own blog posts, and I use another Emacs package called simple-httpd to create a simple web server — as the name implies! — .
The issue I was having was that I had to rebuild the html
files from the org
files every time I wanted to see the output.
I wrote a simple shell script to accomplish this, but still, you need to run it manually.
You can see now how entr can fits into this workflow.
Why don't I use entr to monitor my org
files and make it run the build.sh
script whenever I make a change 😀?
find . -iname "*.org" | entr ./build.sh
And that's it, it's that simple.
All I have to do now is to write my posts, save them, and then reload the web page to see the results.
Wonderful.