Created
February 11, 2023 10:33
-
-
Save lorenzo-stoakes/3b375ebfca6b1309d5f2d5e33d48f296 to your computer and use it in GitHub Desktop.
inotify script for mm-book LaTeX build
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 | |
set -e; set -o pipefail | |
# Thanks to https://stackoverflow.com/a/246128 | |
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )" | |
cd ${SCRIPT_DIR} | |
[[ -z $1 ]] || ${SCRIPT_DIR}/build.sh $1 | |
# Now watch for file changes. | |
inotifywait -r -m chapters/ book.tex -e close_write 2>/dev/null | | |
while read directory action file; do | |
# If not in directory (e.g. book.tex) then first | |
# field is the filename. | |
[[ -n "$file" ]] || file=$directory | |
[[ "$file" =~ .tex$ ]] || continue | |
if [[ "$file" =~ ^shared ]]; then | |
${SCRIPT_DIR}/build-all.sh quick || true | |
continue | |
fi | |
if [[ "$file" =~ -chap.tex$ ]]; then | |
file=${file%"-chap.tex"}.tex | |
fi | |
quick=quick | |
if [[ "$file" =~ ^book ]]; then | |
unset quick | |
fi | |
./build.sh "${file%.*}" $quick || true | |
# Hit r in mupdf to refresh. | |
xdotool search --class Mupdf windowactivate --sync %1 \ | |
key r windowactivate $(xdotool getactivewindow) || true | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment