summaryrefslogtreecommitdiffstats
path: root/build-generic.sh
blob: cefc9f40277f256bd75a73ea8c687e5a64a3dff8 (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
#!/bin/sh
# shellcheck disable=1003

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

long='help,open'
short='ho'

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 generic cover letter using the provided company name and address.

		        USAGE:
		            $SCRIPT <COMPANY> <ADDRESS> [OPTION ...]

		        OPTIONS:
		            -o, --open            Open PDF after building
		            -h, --help            Show this help.

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

open=false
while true; do
	case "$1" in
	-h | --help)
		help
		exit 0
		;;
	-o | --open)
		open=true
		shift
		;;
	--)
		shift
		break
		;;
	*)
		exit 1
		;;
	esac
done

if [ "$#" -eq 0 ]; then
	echo 'Error: Missing name and address'
	help
	exit 1
fi

name=$1
address=$2
shift 2

latexmk src/generic/cover_letter.tex -usepretex="\def\companyname{$name}\def\companyaddress{$address}" -g -jobname=custom_cover_letter "$@"
cp src/generic/custom_cover_letter.pdf src/cover_letter.pdf

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