This scribble covers a utility I've been gradually extending, which is handy for solving
a common automization problem of
This can be things like:
The script is provided in its entirety below, which I'll leave to the especially interested to go through (70% of it is just parsing parameters).
You can check it out as a github gist here.
Whenever I write scripts in an of these languages, I don't have the syntax at my fingertips, so I stumble a bit.
Assuming the file is an executable and has a
The default is checking the modified timestamp. However, you can request
to look at the content itself using the
Say you are monitoring a Wavefront OBJ file, and want to convert it to
some binary representation using a utility called
Monitoring a file and executing a different command allows for automatic recompiling.
Automatic execution when compilation succeeds (note that you have to escape
Monitoring multiple files, using the
watchfile -i main.cpp widget.h widget.cpp \ -e g++ -Wall main.cpp -o main
Monitoring multiple files, and building with make
Finding and monitoring all source files, and building with make
For instance, say you want to monitor the forecast for northern lights in Europe. Here is how to get the Aurora Borealis intensity level forecast, from the Geophysical Institute at UoAF:
curl -s http://www.gi.alaska.edu/AuroraForecast/Europe/ | \ grep -oP 'Europe_\d+' | grep -oP '\d+$'
Let's use the
watchfile -d 900 \ -s "curl -s http://www.gi.alaska.edu/AuroraForecast/Europe/ | \ grep -oP 'Europe_\d+' | grep -oP '\d+$' \ -e notify-send "Northern lights intensity changed"
Let's now modify it to store the intensity value to a temporary file, and then display this value in the pop-up:
watchfile -d 900 \ -s "curl -s http://www.gi.alaska.edu/AuroraForecast/Europe/ | \ grep -oP 'Europe_\d+' | grep -oP '\d+$' | tee /tmp/auroravalue" \ -e cat /tmp/auroravalue | xargs notify-send \ "Northern lights intensity changed to: "
In example 3, I mentioned that if you list files to
monitor using the
To circumvent this, we use the
watchfile -s \ "find . -name '*.cpp' -or -name '*.h' | xargs stat -c %Y" \ -e make \&\& ./main
Alternatively, to output the content of all relevant files (similar to the
watchfile -s \ "find . -name '*.cpp' -or -name '*.h' | xargs cat" \ -e make \&\& ./main