summary refs log tree commit diff
path: root/bin/latexmk
blob: 61b68f57375ed5a1099c0cf943f5b49159c31f43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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'