forked from posquit0/Awesome-CV
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcv
More file actions
executable file
ยท390 lines (325 loc) ยท 13.7 KB
/
cv
File metadata and controls
executable file
ยท390 lines (325 loc) ยท 13.7 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#!/usr/bin/env bash
set -euo pipefail
#โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# CV Profile Manager
# Manage per-company CV / Cover Letter profiles.
#
# Each profile stores the files that change between job applications:
# config.tex, letter_config.tex, sections/*.tex, and compiled PDFs.
#
# Shared structural files (src/main.tex, src/coverletter.tex, src/awesome-cv.cls)
# are NOT profiled โ they are common infrastructure tracked by git.
#โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROFILES_DIR="$SCRIPT_DIR/profiles"
ACTIVE_FILE="$SCRIPT_DIR/.active_profile"
SECTIONS_DIR="$SCRIPT_DIR/sections"
BUILD_DIR="$SCRIPT_DIR/build"
# Files that compose a profile
ROOT_FILES=(config.tex letter_config.tex)
SECTION_FILES=(summary.tex experience.tex skills.tex letter_body.tex education.tex certificates.tex honors.tex)
# โโ Colors โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
RED=$'\033[0;31m'
GREEN=$'\033[0;32m'
YELLOW=$'\033[0;33m'
CYAN=$'\033[0;36m'
BOLD=$'\033[1m'
DIM=$'\033[2m'
RESET=$'\033[0m'
# โโ Helpers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
get_current() {
if [[ -f "$ACTIVE_FILE" ]]; then
cat "$ACTIVE_FILE"
else
echo ""
fi
}
die() { echo -e "${RED}Error:${RESET} $*" >&2; exit 1; }
profile_exists() {
[[ -d "$PROFILES_DIR/$1" ]]
}
available_profiles() {
ls "$PROFILES_DIR" 2>/dev/null | tr '\n' ' '
}
# โโ Commands โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
cmd_list() {
local current
current=$(get_current)
if [[ ! -d "$PROFILES_DIR" ]] || [[ -z "$(ls -A "$PROFILES_DIR" 2>/dev/null)" ]]; then
echo "No profiles found. Create one with: ./cv save <name>"
return
fi
printf "\n${BOLD} Profiles${RESET}\n\n"
for dir in "$PROFILES_DIR"/*/; do
[[ -d "$dir" ]] || continue
local name
name=$(basename "$dir")
# Active marker
local marker=" "
[[ "$name" == "$current" ]] && marker="${GREEN}โธ ${RESET}"
# PDF indicator
local pdf_status="${DIM}no PDFs${RESET}"
if [[ -f "$dir/Weize_Yuan_CV.pdf" ]] && [[ -f "$dir/Weize_Yuan_Cover_Letter.pdf" ]]; then
pdf_status="${GREEN}CV + CL${RESET}"
elif [[ -f "$dir/Weize_Yuan_CV.pdf" ]]; then
pdf_status="${YELLOW}CV only${RESET}"
fi
# Count customized section files
local sec_count=0
for f in "${SECTION_FILES[@]}"; do
[[ -f "$dir/sections/$f" ]] && ((sec_count++))
done
printf " %b%-16s %b ${DIM}(%d sections)${RESET}\n" "$marker" "$name" "$pdf_status" "$sec_count"
done
echo
}
cmd_use() {
local profile="${1:?Usage: ./cv use <profile>}"
profile_exists "$profile" || die "Profile '$profile' not found. Available: $(available_profiles)"
local profile_dir="$PROFILES_DIR/$profile"
# Copy root files
for f in "${ROOT_FILES[@]}"; do
[[ -f "$profile_dir/$f" ]] && cp "$profile_dir/$f" "$SCRIPT_DIR/$f"
done
# Copy section files
mkdir -p "$SECTIONS_DIR"
for f in "${SECTION_FILES[@]}"; do
[[ -f "$profile_dir/sections/$f" ]] && cp "$profile_dir/sections/$f" "$SECTIONS_DIR/$f"
done
echo "$profile" > "$ACTIVE_FILE"
echo -e "${GREEN}โ${RESET} Loaded profile: ${BOLD}$profile${RESET}"
}
cmd_save() {
local profile="${1:-$(get_current)}"
[[ -n "$profile" ]] || die "No profile name given and no active profile.\nUsage: ./cv save <profile>"
local profile_dir="$PROFILES_DIR/$profile"
mkdir -p "$profile_dir/sections"
# Copy root files
for f in "${ROOT_FILES[@]}"; do
[[ -f "$SCRIPT_DIR/$f" ]] && cp "$SCRIPT_DIR/$f" "$profile_dir/$f"
done
# Copy section files
for f in "${SECTION_FILES[@]}"; do
[[ -f "$SECTIONS_DIR/$f" ]] && cp "$SECTIONS_DIR/$f" "$profile_dir/sections/$f"
done
# Copy PDFs if available
for pdf in "$BUILD_DIR"/*.pdf; do
[[ -f "$pdf" ]] && cp "$pdf" "$profile_dir/"
done
echo "$profile" > "$ACTIVE_FILE"
echo -e "${GREEN}โ${RESET} Saved profile: ${BOLD}$profile${RESET}"
}
cmd_build() {
local profile="${1:-}"
# No profile specified โ build current working version
if [[ -z "$profile" ]]; then
echo -e "${CYAN}Building current working version...${RESET}"
make -C "$SCRIPT_DIR" all
return
fi
profile_exists "$profile" || die "Profile '$profile' not found. Available: $(available_profiles)"
local profile_dir="$PROFILES_DIR/$profile"
# โโ Snapshot current state โโ
local tmp_dir
tmp_dir=$(mktemp -d)
trap "rm -rf '$tmp_dir'" EXIT
for f in "${ROOT_FILES[@]}"; do
[[ -f "$SCRIPT_DIR/$f" ]] && cp "$SCRIPT_DIR/$f" "$tmp_dir/$f"
done
mkdir -p "$tmp_dir/sections"
for f in "${SECTION_FILES[@]}"; do
[[ -f "$SECTIONS_DIR/$f" ]] && cp "$SECTIONS_DIR/$f" "$tmp_dir/sections/$f"
done
local prev_profile
prev_profile=$(get_current)
# โโ Build target profile โโ
echo -e "${CYAN}Building profile: ${BOLD}$profile${RESET}"
cmd_use "$profile" > /dev/null
make -C "$SCRIPT_DIR" all
# Save PDFs back to profile
for pdf in "$BUILD_DIR"/*.pdf; do
[[ -f "$pdf" ]] && cp "$pdf" "$profile_dir/"
done
# โโ Restore previous state โโ
for f in "${ROOT_FILES[@]}"; do
[[ -f "$tmp_dir/$f" ]] && cp "$tmp_dir/$f" "$SCRIPT_DIR/$f"
done
for f in "${SECTION_FILES[@]}"; do
[[ -f "$tmp_dir/sections/$f" ]] && cp "$tmp_dir/sections/$f" "$SECTIONS_DIR/$f"
done
[[ -n "$prev_profile" ]] && echo "$prev_profile" > "$ACTIVE_FILE"
trap - EXIT
rm -rf "$tmp_dir"
echo -e "${GREEN}โ${RESET} Built profile: ${BOLD}$profile${RESET} โ profiles/$profile/"
}
cmd_new() {
local profile="${1:?Usage: ./cv new <profile>}"
profile_exists "$profile" && die "Profile '$profile' already exists. Use './cv save $profile' to update it."
cmd_save "$profile"
echo -e " ${DIM}Tip: edit files, then run './cv save $profile' to update${RESET}"
}
cmd_diff() {
local a="${1:?Usage: ./cv diff <a> [b]}"
local b="${2:-}"
profile_exists "$a" || die "Profile '$a' not found."
local dir_a="$PROFILES_DIR/$a"
if [[ -n "$b" ]]; then
# Compare two profiles
profile_exists "$b" || die "Profile '$b' not found."
local dir_b="$PROFILES_DIR/$b"
echo -e "${BOLD}Comparing profiles: ${CYAN}$a${RESET} vs ${CYAN}$b${RESET}\n"
diff -rq --exclude='*.pdf' "$dir_a" "$dir_b" 2>/dev/null || true
else
# Compare profile against current working files
echo -e "${BOLD}Comparing profile ${CYAN}$a${RESET} with current working files:\n"
local has_diff=false
for f in "${ROOT_FILES[@]}"; do
if ! diff -q "$dir_a/$f" "$SCRIPT_DIR/$f" &>/dev/null; then
echo -e " ${YELLOW}โ ${RESET} $f"
has_diff=true
else
echo -e " ${GREEN}=${RESET} $f"
fi
done
for f in "${SECTION_FILES[@]}"; do
if ! diff -q "$dir_a/sections/$f" "$SECTIONS_DIR/$f" &>/dev/null; then
echo -e " ${YELLOW}โ ${RESET} sections/$f"
has_diff=true
else
echo -e " ${GREEN}=${RESET} sections/$f"
fi
done
echo
if $has_diff; then
echo -e " ${DIM}Use 'diff profiles/$a/<file> <file>' for details${RESET}"
else
echo -e " ${GREEN}Working files match profile '$a'${RESET}"
fi
fi
}
cmd_current() {
local current
current=$(get_current)
if [[ -z "$current" ]]; then
echo "No active profile. Use './cv use <profile>' to load one."
else
echo -e "Active profile: ${BOLD}$current${RESET}"
fi
}
cmd_delete() {
local profile="${1:?Usage: ./cv delete <profile>}"
profile_exists "$profile" || die "Profile '$profile' not found."
local current
current=$(get_current)
[[ "$profile" == "$current" ]] && die "Cannot delete the active profile. Switch first with './cv use <other>'."
read -rp "Delete profile '$profile'? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || { echo "Cancelled."; return; }
rm -rf "${PROFILES_DIR:?}/$profile"
echo -e "${GREEN}โ${RESET} Deleted profile: ${BOLD}$profile${RESET}"
}
# โโ Interactive Menu โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
cmd_interactive() {
local current
current=$(get_current)
local current_label=""
[[ -n "$current" ]] && current_label=" ${DIM}(active: ${RESET}${GREEN}$current${RESET}${DIM})${RESET}"
printf "\n${BOLD} CV Profile Manager${RESET}%b\n\n" "$current_label"
local -a options=(
"list List all profiles"
"use Load a profile"
"save Save current files to profile"
"build Build PDFs"
"new Create new profile"
"diff Compare profiles"
"current Show active profile"
"delete Delete a profile"
"help Show full usage"
"quit Exit"
)
local i=1
for opt in "${options[@]}"; do
local cmd="${opt%% *}"
local desc="${opt#* }"
# Remove leading whitespace from desc
desc="${desc#"${desc%%[![:space:]]*}"}"
printf " ${CYAN}%2d${RESET}) %-10s %s\n" "$i" "$cmd" "$desc"
((i++))
done
echo
read -rp " Choose [1-${#options[@]}]: " choice
echo
case "$choice" in
1) cmd_list ;;
2)
if [[ ! -d "$PROFILES_DIR" ]] || [[ -z "$(ls -A "$PROFILES_DIR" 2>/dev/null)" ]]; then
die "No profiles found."
fi
cmd_list
read -rp " Profile name: " profile_name
[[ -n "$profile_name" ]] && cmd_use "$profile_name"
;;
3) cmd_save "${1:-}" ;;
4)
read -rp " Profile name (empty = current): " profile_name
cmd_build "$profile_name"
;;
5)
read -rp " New profile name: " profile_name
[[ -n "$profile_name" ]] && cmd_new "$profile_name" || die "Profile name required."
;;
6)
read -rp " First profile: " pa
read -rp " Second profile (empty = current files): " pb
cmd_diff "$pa" "$pb"
;;
7) cmd_current ;;
8)
cmd_list
read -rp " Profile to delete: " profile_name
[[ -n "$profile_name" ]] && cmd_delete "$profile_name"
;;
9) usage ;;
10|q|quit) echo "Bye." ; exit 0 ;;
*) die "Invalid choice: $choice" ;;
esac
}
# โโ Usage โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
usage() {
cat <<EOF
${BOLD}CV Profile Manager${RESET} โ switch between per-company CV/Cover Letter versions
${BOLD}Usage:${RESET} ./cv <command> [args]
${BOLD}Commands:${RESET}
${CYAN}list${RESET} List all profiles (active marked with โธ)
${CYAN}use${RESET} <profile> Load a profile into the working directory
${CYAN}save${RESET} [profile] Save current working files to a profile
${CYAN}build${RESET} [profile] Build PDFs (current if omitted, or specific profile)
${CYAN}new${RESET} <profile> Create a new profile from current working files
${CYAN}diff${RESET} <a> [b] Compare two profiles (b = current working if omitted)
${CYAN}current${RESET} Show the active profile name
${CYAN}delete${RESET} <profile> Delete a profile
${BOLD}Examples:${RESET}
./cv list # See all profiles
./cv use porsche # Switch to Porsche version
./cv save # Save changes to current profile
./cv build honeywell # Build Honeywell PDFs without switching
./cv new siemens # Create new profile from current files
./cv diff porsche valeo # Compare two profiles
${BOLD}What's in a profile:${RESET}
config.tex, letter_config.tex, sections/*.tex, and compiled PDFs.
Structural files (src/main.tex, src/coverletter.tex, src/awesome-cv.cls) are shared.
EOF
}
# โโ Dispatch โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
case "${1:-}" in
list) cmd_list ;;
use) cmd_use "${2:-}" ;;
save) cmd_save "${2:-}" ;;
build) cmd_build "${2:-}" ;;
new) cmd_new "${2:-}" ;;
diff) cmd_diff "${2:-}" "${3:-}" ;;
current) cmd_current ;;
delete) cmd_delete "${2:-}" ;;
-h|--help|help) usage ;;
"") cmd_interactive ;;
*) echo -e "${RED}Unknown command:${RESET} $1"; usage; exit 1 ;;
esac