diff options
| author | Robert Günzler <r@gnzler.io> | 2021-06-01 13:24:35 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2021-06-01 14:43:46 +0200 |
| commit | 67b658bc156087a7a007e3e4759037620c400d8c (patch) | |
| tree | 2dbaa98f6626c3dbaeaa380dd48b3e3632cbd7fa | |
| parent | e459d2c9b6448ae1a2e89bc1f1115a1ad4235dd0 (diff) | |
bin/latexmk: allow setting a different ENGINE and VIEWER
also make sure we are *nix cross-compatible and fix some shellcheck warnings
| -rwxr-xr-x | bin/latexmk | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/bin/latexmk b/bin/latexmk index 61b68f5..79d497e 100755 --- a/bin/latexmk +++ b/bin/latexmk @@ -3,38 +3,49 @@ set -e [ -n "$DEBUG" ] && set -x +ENGINE=${ENGINE:-tectonic} +ENGINE_ARGS=${ENGINE_ARGS:-} +VIEWER=${VIEWER:-zathura} + reexec= +nocolor= while getopts 1Rnh opt; do case "$opt" in - 1) entr_args='-z' ;; - R) reexec=1 ;; - n) nocolor=1 ;; - h|?) printf "usage: %s [-h]\n" "$(basename "$0")" - printf "\n" - printf " -1 \t oneshot mode\n" - printf " -n \t no color\n" - printf "\n" - exit 2 ;; + 1) entr_args='-z' ;; + R) reexec=1 ;; + n) nocolor=1 ;; + h | ?) + printf "usage: %s [-h]\n" "$(basename "$0")" + printf "\n" + printf " -1 \t only run once\n" + printf " -n \t no color\n" + printf "\n" + exit 2 + ;; esac done shift $((OPTIND - 1)) if [ -n "${reexec}" ]; then - pdf=$(readlink -f -- $(printf $1 | sed 's/\.tex/\.pdf/')); + pdf=$(realpath "$(printf "%s" "$1" | sed 's/\.tex/\.pdf/')") log() { if [ -n "${nocolor}" ]; then - printf "$(tput setaf 2)!>>>$(tput sgr0) $1\n" + printf "%s!==>%s %s\n" "$(tput setaf 2)" "$(tput sgr0)" "$1" else - printf "=> $1\n" + printf "==> %s\n" "$1" fi } - log "running tectonic" - tectonic --chatter=minimal "$1" - if ! pgrep -fx "zathura $pdf" >/dev/null; then - log "running zathura" - swaymsg exec zathura "$pdf" >/dev/null + + # compile the document + log "running ${ENGINE}" + ${ENGINE} ${ENGINE_ARGS} "$1" + + if ! pgrep -fx "${VIEWER} $pdf" >/dev/null; then + # spawn the viewer + log "running ${VIEWER}" + (${VIEWER} "$pdf" >/dev/null 2>&1) & fi - printf -- '!! ' + exit 0 fi |