summaryrefslogtreecommitdiffstats
path: root/build.sh
blob: 99c4b0589fadf100129c0e8a865a503cf9bf2ccf (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
101
102
103
104
105
#!/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
while true; do
	case "$1" in
	-h | --help)
		help
		exit 0
		;;
	-o | --open)
		open=true
		shift
		;;
	-A | --all)
		all=true
		shift
		;;
	-n | --name)
		name=$2
		shift 2
		;;
	-a | --address)
		address=$2
		shift 2
		;;
	--)
		shift
		break
		;;
	*)
		exit 1
		;;
	esac
done

if $all; then
	for f in src/*/cover_letter.tex; do
		latexmk "$f"
	done
fi

if [ -n "$name" ]; then
	if [ -n "$address" ]; then
		company=generic
		set -- "$@" -usepretex="\def\companyname{$name}\def\companyaddress{$address}" -g
	elif [ -e "src/$name/cover_letter.tex" ]; then
		company="$name"
	else
		error "Directory $name not found"
	fi
else
	company=generic
	set -- "$@" -g
fi

latexmk "src/resume.tex"
latexmk "src/$company/cover_letter.tex" -cd- -outdir="src" -auxdir="src" "$@"
pdfunite src/cover_letter.pdf src/resume.pdf src/cover_letter-resume.pdf

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