Last active
May 16, 2018 20:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?