-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude.sh
executable file
·82 lines (69 loc) · 1.32 KB
/
include.sh
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
#!/bin/bash
RESUME_URL=$(yq -crM '.links | map(select(.name=="Resume")) | .[].url' data.yaml)
export RESUME_URL
PDF=${RESUME_URL}joehillen-resume.pdf
export PDF
function loop() {
while read -r line; do
"$@" "$line"
done
}
function trim() {
local s
local arg
local left
local right
# TODO getopt
while [[ $1 ]]; do
case "$1" in
-l | --left)
left=true
;;
-r | --right)
right=true
;;
--)
shift
arg="$*"
break
;;
*)
arg="$*"
break
;;
esac
shift
done
if [[ $left != true && $right != true ]]; then
left=true
right=true
fi
# if no arguments, read from STDIN
while [[ $arg ]] || IFS=$'\n' read -r s; do
# XXX: $arg is to avoid defining a function for this block
[[ $arg ]] && s="$arg"
# remove leading whitespace characters
if [[ $left = true ]]; then
s="${s#"${s%%[![:space:]]*}"}"
fi
# remove trailing whitespace characters
if [[ $right = true ]]; then
s="${s%"${s##*[![:space:]]}"}"
fi
printf '%s\n' "$s"
[[ $arg ]] && break
done
}
function get() {
yq -cMr "try .$1 // empty" data.yaml
}
function edu() {
get "education.$*"
}
function check() {
local path="$1"
! grep -q null "$path" || {
echo "$path contains null values"
exit 1
}
}