Skip to content

Instantly share code, notes, and snippets.

@jbaiter
Last active May 16, 2018 20:54
Show Gist options
  • Save jbaiter/5110434 to your computer and use it in GitHub Desktop.
Save jbaiter/5110434 to your computer and use it in GitHub Desktop.
Wrapper script around Sigil to support version control workflows. Change $SIGIL to match your system's settings.
#!/bin/bash
# USAGE
# =====
# $ sigil.sh <directory>
# Change this to match your system
SIGIL="/usr/local/bin/sigil"
# --------------------------------
# Checks if the temporary epub has been modified and updates the
# project tree if so.
function update {
if [[ $(stat -c %Y $tmpfile) != $lastmod ]]; then
unzip -q -o -u $tmpfile
lastmod=$(stat -c %Y $tmpfile)
fi
}
file=$1
# Handle regular epub files
if [[ -f "$file" && "$file" == *.epub ]]; then
$SIGIL "$file"
else
workdir=$1
# Remember source directory
origdir=$(pwd)
# Switch to project directory
cd "$workdir"
# Create temporary epub
tmpfile=$(mktemp -u -t sigil.XXXXXX.epub)
zip -q -r $tmpfile *
# Remember last modification time
lastmod=$(stat -c %Y $tmpfile)
# Start Sigil
$SIGIL $tmpfile &
sigil_pid=$!
# Periodically update the working directory as long as Sigil is running
while kill -0 $sigil_pid 2>/dev/null; do
update
sleep 1
done
# Update the project tree
unzip -q -o -u $tmpfile
rm $tmpfile
# Return to source directory
cd $origdir
fi
@piffy
Copy link

piffy commented Mar 4, 2014

How should one use it? Use this on an unzipped directory (which is under revision control), so that it creates an epub on the fly? Or as a github filter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment