14 Feb 2018
Automatically trigger commands on source change
Sometimes, you need to write a source file and “compile” (as in “run a generic script on it”) each time you edit it, just to see the final result.
On Ubuntu, you can use the inotifywait command to keep an eye on filesystem operations.
1 sudo apt install inotify-tools
You can create a simple bash file such as this:
1 2 3 4 5 6 #!/bin/sh inotifywait -m . -e modify | while read path action file; do # Do something... done
I often use it when building markdown slides.
I just create a
update.sh script with the following content:
1 2 3 4 5 6 7 8 #!/bin/sh inotifywait -m . -e modify | while read path action file; do echo "[*] Generating slides..." pandoc -t beamer $file -V theme:metropolis -o slides.pdf echo "[*] Done." done
This script will try to run
pandoc on any saved file.
You just have to launch the script (
./update.sh &, after making it executable –
chmod +x update.sh) and then open your slides (
It will update automatically every time you save your
Keep the generated PDF file in a separate screen for best results.