summaryrefslogtreecommitdiffstats
path: root/build.sh
blob: e891a604f041b0ab9014a9c213a22f573ce70fcc (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh

CDPATH='' cd -- "$(dirname -- "$0")" || exit

SCRIPT="$(basename "$0")"

long='help,open,all,name:,address:'
short='hoAn:a:'

if ! opts="$(getopt -o $short -l $long -n "$SCRIPT" -- "$@")"; then
	exit 1
fi

eval set -- "$opts"

help() {
	cat <<-EOF
		        $SCRIPT
		        Toby Vincent <tobyv@tobyvin.dev>

		        $SCRIPT
		            Builds resume and cover letter.

		        USAGE:
		            $SCRIPT [OPTIONS...] <COMPANY> <ADDRESS> -- [LATEXMK_OPTS...]

		        OPTIONS:
		            -A, --all             Build all cover letters
		            -n, --name            Specify a company name to use for generic cover letter
		            -a, --address         Specify a company address to use for generic cover letter
		            -o, --open            Open combined PDF after building
		            -h, --help            Show this help.

		        EXAMPLES:
		            $SCRIPT -n "Chuck's Clucks"  -a "Cluckville, KY" --open
	EOF
}

error() {
	printf 'Error: %s' "$1" 1>&2
	help
	exit 1
}

open=false
all=false
path="."
pretex=""
while true; do
	case "$1" in
	-h | --help)
		help
		exit 0
		;;
	-o | --open)
		open=true
		shift
		;;
	-A | --all)
		all=true
		shift
		;;
	-n | --name)
		if [ -e "$2/cover_letter.tex" ]; then
			path=$2
		else
			pretex="${pretex:--usepretex=}\def\companyname{$2}"
		fi
		shift 2
		;;
	-a | --address)
		pretex="${pretex:--usepretex=}\def\companyaddress{$2}"
		shift 2
		;;
	--)
		shift
		break
		;;
	*)
		exit 1
		;;
	esac
done

if $all; then
	for f in ./*/; do
		if [ -e "$f/cover_letter.tex" ]; then
			latexmk "$f/cover_letter.tex" -outdir="$f" -auxdir="$f"
		fi
	done
fi

latexmk "resume.tex"
latexmk -g "$path/cover_letter.tex" "$pretex"

pdfunite cover_letter.pdf resume.pdf cover_letter-resume.pdf

if $open; then
	xdg-open cover_letter-resume.pdf
fi