This is a short bash script I wrote in order to automatically build the HTML version of some documentation using the Sphinx documentation system upon change of any file inside the documentation directory.

The script should be placed inside the documentation directory (the same containing the Sphinx Makefile, etc). Its behavior is quite straight-forward; what it does is:

  1. Retrieve the directory containing the script, and use as $WORKDIR
  2. Wait for a modify/create/delete event on the $WORKDIR
  3. Use the makefile to build html documentation into $WORKDIR
  4. Continue the infinite loop until stopped by CTRL-C
## Automatically build Sphinx documentation upon file change
## Copyright (c) 2011 Samuele ~redShadow~ Santi - Under GPL

WORKDIR="$( dirname "$0" )"
while :; do
    ## Wait for changes
    inotifywait -e modify,create,delete -r "$WORKDIR"
    ## Make html documentation
    make -C "$WORKDIR" html

Update: improved version

This is the improved version I'm using, as of 2012-11-06 (in fact, this very same page has been built by a similar script).

## Automatically build Sphinx documentation upon file change
## Copyright (c) 2011-2012 Samuele ~redShadow~ Santi - Under GPL

if ! which inotifywait &>/dev/null; then
    echo "ERROR: Program 'inotifywait' is not installed"
    exit 1

## Gray out the output
fade() {
    sed 's/^\(.*\)$/\x1b[1;30m\1\x1b[0m/'

while :; do
    ## Wait for changes in current directory
    inotifywait -r -e modify,close_write,moved_to,moved_from,move,create,delete ./hackzine/ 2>&1 | fade

    ## Run the command and retrieve return code

    ## Try to send a notification using libnotify
    if which notify-send &>/dev/null; then
        if [ "$RET" == "0" ]; then
            TITLE="Make execution successful"
            TITLE="Make execution failed"
        notify-send "$TITLE" \
            "Command was: '$ARGS'\n\nPWD: $(pwd)\n\nReturn code: $RET" \
            --icon="$ICO" \
            2>&1 | fade

Example usage would be:

./ make html