Script to run build script on save Script to run build script on save

March 5, 2021

debian bash jigsaw

Today I decided I wanted a script to auto build the site on each save of this jigsaw blog. I was playing with the css yesterday and liked the simplicity of the npm watch command, but wanted something similar for the build.sh script.

I have been meaning to use entr for a while see entr docs and this seemed perfect for the job.

    #!/bin/bash

    find /var/www/jigsaw-blog/source/_posts/   | entr sh -c './build.sh';

One problem i found was the max_user_watches was set too low, so running the following command as root, increases the number of file nodes this is allowed to watch. And it worked perfectly after that.

    echo 100000 | tee /proc/sys/fs/inotify/max_user_watches

Another problem i found is that it breaks if you rename a file, as it monitors for changes, but it cannot deal with that.

This is my build.sh script. It runs the local build but can also run with these flags too:

--npm           runs the laravel mix webpack build
--production    generates the production build

It uses espeak to announce it is building (a bit like command and conquer!) and then xdotool to reload the firefox browser.

#!/bin/bash -e

# espeak "Building"

for arg in "$@"
do
    if [ "$arg" == "--npm" ] 
    then
        echo "Running npm run production"
        espeak " running en pee em "
        npm run production
    fi
done

espeak "building Local"

 ./vendor/bin/jigsaw -vvv build 

for arg in "$@"
do
    if [ "$arg" == "--production" ] 
    then
        espeak "building production"
        ./vendor/bin/jigsaw build production -vvv
    fi
done

espeak "Finished"

# reload firefox in background
CURRENT_WID=$(xdotool getwindowfocus)
WID=$(xdotool search --name "Mozilla Firefox")
xdotool windowactivate $WID
xdotool key F5
# return to the editor (i prefer it to keep the browser at the front so comment this out!)
xdotool windowactivate $CURRENT_WID


If you would like to contact me with this form on londinium.com, ilminster.net or via Twitter @andylondon