So far, so good. Everything works fine, every push to the remote generates the site. The only thing drawback, is that in order to preview the site, one has either to push…​ or to type the whole command-line every time. The bash history helps somewhat, until some other command is required.

As a user, I want to preview the HTML automatically in order to keep me from writing the same command-line over and over. — Me

This one a bit is harder, because it’s not related to Asciidoctor. A full-blown solution with LiveReload and everything would be probably be overkill (read that I’m too lazy). But I’ll be happy enough with a watch over the local file system, and the trigger of a command when changes are detected. As my laptop runs on OSX, here’s a solution that "works on my machine". This is based on the launchd process and the plist format.

This format is XML-based, but "weakly-typed" and based on the order of elements. For example, key value pairs are defined as such:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version= "1.0" > <dict> <key> key1 </key> <string> value1 </string> <key> key2 </key> <string> value2 </string> </dict>

A couple of things I had to find out on my own - I had no prior experience with launchd:

A .plist file should be named as per the key named Label . It should be located in the ~/Library/LaunchAgents/ folder. WatchPaths key associated with the array of paths to watch. In this specific case, the most important part is to understand how to watch the filesystem . It’s achieved with thekey associated with the array of paths to watch. The second most important part is the command to execute, ProgramArguments . The syntax is quite convoluted: every argument on the command line (as separated by spaces) should be an element in an array. It seems the $PATH is not initialized with environment variables of my own user, so the full path to the executable should be used. As debugging is mandatory - at least with the first few runs, feel free to use StandardErrorPath and StandardOutPath to respectively write standard err and out in files.

The final .plist looks something like that:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version= "1.0" > <dict> <key> Label </key> <string> ch.frankel.generatejaveecours.plist </string> <key> WorkingDirectory </key> <string> /Users/frankel/projects/course/javaee </string> <key> Program </key> <string> /usr/local/bin/bundle </string> <key> ProgramArguments </key> <array> <string> /usr/local/bin/bundle </string> <string> exec </string> <string> asciidoctor-revealjs </string> <string> -a </string> <string> revealjs_history=true </string> <string> -a </string> <string> revealjs_theme=white </string> <string> -a </string> <string> revealjs_slideNumber=true </string> <string> -a </string> <string> linkcss </string> <string> -a </string> <string> customcss=../style.css </string> <string> -a </string> <string> revealjsdir=https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.5.0 </string> <string> cours/*.adoc </string> </array> <key> WatchPaths </key> <array> <string> /Users/frankel/projects/course/javaee/cours </string> </array> <key> StandardErrorPath </key> <string> /tmp/asciidocgenerate.err </string> <key> StandardOutPath </key> <string> /tmp/asciidocgenerate.out </string> </dict> </plist>

To finally launch the daemon, use the launchctl command: