#!/bin/bash set -e [ -n "$DEBUG" ] && set -x reexec= 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 ;; esac done shift $((OPTIND - 1)) if [ -n "${reexec}" ]; then pdf=$(readlink -f -- $(printf $1 | sed 's/\.tex/\.pdf/')); log() { if [ -n "${nocolor}" ]; then printf "$(tput setaf 2)!>>>$(tput sgr0) $1\n" else printf "=> $1\n" 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 fi printf -- '!! ' exit 0 fi if [ -z "$1" ]; then ls *.tex else [ -f "$1" ] && printf "$1\n" ls *.tex fi | entr ${entr_args} -ns 'latexmk -R $0'