-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_resume.sh
More file actions
373 lines (330 loc) · 10.3 KB
/
make_resume.sh
File metadata and controls
373 lines (330 loc) · 10.3 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/bin/sh
[ ! -z "$srcPL_resume" ] && [ $srcPL_resume -eq 1 ] && return 0
[ -z "$git_dir" ] && git_dir=$(cd $(dirname $BASH_SOURCE)/../..; pwd)
# ----------
# Get baSHic
# ----------
get_baSHic(){
local repo repo_dir
repo=baSHic
repo_dir="$git_dir/$repo"
if [ ! -d "$repo_dir" ]; then
cd "$git_dir"
git clone https://github.com/pllittle/$repo.git >&2
[ ! $? -eq 0 ] && echo -e "Error cloning $repo" >&2 && return 1
else
cd "$repo_dir"
git pull >&2
[ ! $? -eq 0 ] && echo -e "Error pulling $repo" >&2 && return 1
fi
cd - > /dev/null
. "$repo_dir/scripts/base.sh"
[ ! $? -eq 0 ] && echo -e "Error src-ing $repo's base" >&2 && return 1
# unset repo repo_dir
}
get_baSHic
# ----------
# Get firstClass
# ----------
getRepoSrc -r firstClass -u pllittle
[ ! $? -eq 0 ] && echo "Error src-ing" >&2 && return 1
# ----------
# Check commands are on PATH
# ----------
for CMD in realpath latexmk; do
unset chk
[ -z "$chk" ] && chk=$(which ${CMD} &> /dev/null; echo $?)
[ ! $chk -eq 0 ] \
&& echo -e "'$CMD' command not found" >&2 \
&& return 1
done
# ----------
# Functions
# ----------
cleanup_tex(){
local orig_dir out_dir ext nfiles
while [ ! -z "$1" ]; do
case $1 in
-o | --out_dir )
shift
out_dir="$1"
;;
esac
shift
done
orig_dir=$(pwd)
cd "$out_dir"
for ext in aux log out fdb_latexmk fls; do
nfiles=$(ls | grep "${ext}$" | wc -l)
[ ! $nfiles -eq 0 ] && rm $(ls | grep "${ext}$")
done
cd "$orig_dir"
}
make_resumeTex(){
local out_dir label_fn res_fn class_fn class_dir
local name email location phone position
local github linkedin orcid
local educate_fn exper_fn objective_fn publish_fn accomplish_fn
local software_fn skills_fn courses_fn present_fn leader_fn proj_fn
local resp cmd compile nAdd n_pct n_miss keyw
compile=0; nAdd=0
while [ ! -z "$1" ]; do
case $1 in
--class_fn )
shift
class_fn="$1"
;;
--compile )
compile=1
;;
--courses_fn )
shift
courses_fn="$1"
;;
--educate_fn )
shift
educate_fn="$1"
;;
--email )
shift
email="$1"
;;
--exper_fn )
shift
exper_fn="$1"
;;
--github )
shift
github="$1"
;;
--label_fn )
shift
label_fn="$1"
;;
--linkedin )
shift
linkedin="$1"
;;
--location )
shift
location="$1"
;;
--name )
shift
name="$1"
;;
-o | --out_dir )
shift
out_dir="$1"
;;
--objective_fn )
shift
objective_fn="$1"
;;
--orcid )
shift
orcid="$1"
;;
--phone )
shift
phone="$1"
;;
--position )
shift
position="$1"
;;
--present_fn )
shift
present_fn="$1"
;;
--publish_fn )
shift
publish_fn="$1"
;;
--accomplish_fn )
shift
accomplish_fn="$1"
;;
--skills_fn )
shift
skills_fn="$1"
;;
--leader_fn )
shift
leader_fn="$1"
;;
--proj_fn )
shift
proj_fn="$1"
;;
--software_fn )
shift
software_fn="$1"
;;
-* )
echo -e "Error: command line input ${red}$1${NC} is invalid" >&2 && return 1
esac
shift
done
# Check inputs
[ -z "$label_fn" ] && label_fn=resume
while [ -z "$out_dir" ]; do
make_menu -c "$yellow" -p "Output directory for latex files?"
read resp
[ -z "$resp" ] && print_noInput && continue
out_dir="$resp"
done
while [ -z "$class_fn" ]; do
make_menu -c "$yellow" -p "Path to a latex class filename?"
read resp
[ -z "$resp" ] && print_noInput && continue
[ ! -f "$resp" ] && echo -e "Error: $resp missing, try again" >&2 && continue
class_fn="$resp"
done
while [ -z "$email" ]; do
make_menu -c "$yellow" -p "Enter a valid email address:"
read resp
[ -z "$resp" ] && print_noInput && continue
[ ! $(echo -e "$resp" | grep "@" | wc -l) -eq 1 ] \
&& echo "Not a valid email, try again" >&2 && continue
email="$resp"
done
while [ -z "$educate_fn" ]; do
make_menu -c "$yellow" -p "Path to a latex filename with education?"
read resp
[ -z "$resp" ] && print_noInput && continue
resp=$(echo -e $resp)
[ ! -f "$resp" ] && echo -e "$resp missing" >&2 && continue
educate_fn="$resp"
done
while [ -z "$exper_fn" ]; do
make_menu -c "$yellow" -p "Path to a latex filename with experiences?"
read resp
[ -z "$resp" ] && print_noInput && continue
[ ! -f "$resp" ] && echo -e "$resp missing" >&2 && continue
exper_fn="$resp"
done
while [ -z "$name" ]; do
make_menu -c "$yellow" -p "What is your name? (e.g. John Doe or Jane Doe, PhD)"
read resp
[ -z "$resp" ] && print_noInput && continue
name="$resp"
done
# Make output directory and subfolders
new_mkdir "$out_dir" "$out_dir/sections"
# Process inputs
class_fn=$(realpath $class_fn)
[ ! $? -eq 0 ] && echo "Error running 'realpath' cmd" >&2 && return 1
class_dir=$(echo $class_fn | sed 's|/|\n|g' | head -n -1 | tr '\n' '/' | sed 's|/$||')
class_fn=$(echo $class_fn | sed 's|.cls$||' | sed 's|/|\n|g' | tail -n 1)
email=$(echo $email | sed 's|_|\\_|g')
[ ! -z "$objective_fn" ] && [ ! -f "$objective_fn" ] && echo -e "$objective_fn missing" >&2 && return 1
[ ! -z "$publish_fn" ] && [ ! -f "$publish_fn" ] && echo -e "$publish_fn missing" >&2 && return 1
[ ! -z "$skills_fn" ] && [ ! -f "$skills_fn" ] && echo -e "$skills_fn missing" >&2 && return 1
[ ! -z "$courses_fn" ] && [ ! -f "$courses_fn" ] && echo -e "$courses_fn missing" >&2 && return 1
[ ! -z "$present_fn" ] && [ ! -f "$present_fn" ] && echo -e "$present_fn missing" >&2 && return 1
[ ! -z "$leader_fn" ] && [ ! -f "$leader_fn" ] && echo -e "$leader_fn missing" >&2 && return 1
[ ! -z "$proj_fn" ] && [ ! -f "$proj_fn" ] && echo -e "$proj_fn missing" >&2 && return 1
[ ! -z "$accomplish_fn" ] && [ ! -f "$accomplish_fn" ] && echo -e "$accomplish_fn missing" >&2 && return 1
[ ! -z "$software_fn" ] && [ ! -f "$software_fn" ] && echo -e "$software_fn missing" >&2 && return 1
# Write resume.tex file
res_fn="$out_dir/$label_fn.tex"
new_rm "$res_fn"
echo -e "\\documentclass[12pt]{$class_fn}\n" >> "$res_fn"
echo -e "% Definitions" >> "$res_fn"
echo -e "\\def\\MyName{$name}" >> "$res_fn"
echo -e "\\def\\MyEmail{$email}" >> "$res_fn"
[ ! -z "$phone" ] && echo -e "\\def\\MyPhone{$phone}" >> "$res_fn"
[ ! -z "$location" ] && echo -e "\\def\\MyLocation{$location}" >> "$res_fn"
[ ! -z "$github" ] && echo -e "\\def\\MyGitHub{$github}" >> "$res_fn"
[ ! -z "$linkedin" ] && echo -e "\\def\\MyLinkedIn{$linkedin}" >> "$res_fn"
[ ! -z "$position" ] && echo -e "\\def\\MyPosition{$position}" >> "$res_fn"
[ ! -z "$orcid" ] && echo -e "\\def\\MyOrcid{$orcid}" >> "$res_fn"
echo -e "\n\\\begin{document}\n" >> "$res_fn"
# Objective/summary
[ ! -z "$objective_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$objective_fn" "$out_dir/sections/objective.tex" \
&& echo -e "\\input{sections/objective}\n" >> "$res_fn"
# Skills
[ ! -z "$skills_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$skills_fn" "$out_dir/sections/skills.tex" \
&& echo -e "\\input{sections/skills}\n" >> "$res_fn"
# Professional Experience
let nAdd=nAdd+1 \
&& cp "$exper_fn" "$out_dir/sections/experience.tex" \
&& echo -e "\\input{sections/experience}\n" >> "$res_fn"
# Education
let nAdd=nAdd+1 \
&& cp "$educate_fn" "$out_dir/sections/education.tex" \
&& echo -e "\\input{sections/education}\n" >> "$res_fn"
# Accomplishments
[ ! -z "$accomplish_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$accomplish_fn" "$out_dir/sections/accomplishments.tex" \
&& echo -e "\\input{sections/accomplishments}\n" >> "$res_fn"
# Projects
let nAdd=nAdd+1 \
&& cp "$proj_fn" "$out_dir/sections/projects.tex" \
&& echo -e "\\input{sections/projects}\n" >> "$res_fn"
# Software
[ ! -z "$software_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$software_fn" "$out_dir/sections/software.tex" \
&& echo -e "\\input{sections/software}\n" >> "$res_fn"
# Publications
[ ! -z "$publish_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$publish_fn" "$out_dir/sections/publications.tex" \
&& echo -e "\\input{sections/publications}\n" >> "$res_fn"
# Courses
[ ! -z "$courses_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$courses_fn" "$out_dir/sections/courses.tex" \
&& echo -e "\\input{sections/courses}\n" >> "$res_fn"
# Presentations
[ ! -z "$present_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$present_fn" "$out_dir/sections/present.tex" \
&& echo -e "\\input{sections/present}\n" >> "$res_fn"
# Leadership
[ ! -z "$leader_fn" ] \
&& let nAdd=nAdd+1 \
&& cp "$leader_fn" "$out_dir/sections/leadership.tex" \
&& echo -e "\\input{sections/leadership}\n" >> "$res_fn"
[ $nAdd -eq 0 ] \
&& echo -e "Hi world\n" >> "$res_fn" \
&& echo -e "Test run\n" >> "$res_fn"
echo -e "\\\end{document}\n" >> "$res_fn"
echo -e "${green}$label_fn.tex${NC} finalized." >&2
# Run check of % usage in experience section
n_pct=$(cat "$out_dir/sections/experience.tex" | grep -v "^%" \
| sed 's|\\%|pct|g' | grep "%" | wc -l)
[ $n_pct -gt 0 ] && echo -e "${yellow}Warning${NC}: Detected use of non-leading char '%' within latex, double check tex experience.tex!" >&2 && return 1
# Check incomplete sections
for keyw in "hfill somewhere" "hfill MMM YYYY"; do
n_miss=$(cat "$out_dir/sections/experience.tex" | grep -v "^%" \
| grep "$keyw" | wc -l)
[ $n_miss -gt 0 ] && echo -e "${yellow}Warning${NC}: Detected incomplete entries (${cyan}${keyw}${NC}) within latex, double check tex experience.tex!" >&2 && return 1
done
if [ $compile -eq 1 ]; then
echo -e "${yellow}Executing latexmk ...${NC}" >&2
export TEXINPUTS="$class_dir"
cleanup_tex -o "$out_dir"
cmd="latexmk"
cmd="$cmd -cd" # change directory to source tex file when processing
cmd="$cmd -output-format=pdf"
cmd="$cmd \"$res_fn\""
# echo -e "cmd = $cmd" >&2
eval $cmd >&2 # > /dev/null
[ ! $? -eq 0 ] && echo "Error in latexmk" >&2 && return 1
cleanup_tex -o "$out_dir"
# new_rm "$out_dir/sections"
[ ! -z "$TEXINPUTS" ] && unset TEXINPUTS
echo -e "PDF located at ${yellow}$out_dir${NC}/${green}$label_fn.pdf${NC}" >&2
fi
return 0
}
srcPL_resume=1
## EOF