-
Notifications
You must be signed in to change notification settings - Fork 1
/
build
executable file
·86 lines (70 loc) · 1.54 KB
/
build
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
#!/usr/bin/env bash
read -r -d '' helptxt <<EOF
This script is used for building these books as a web site:
site
help
watch
For more information, see the README.md file.
EOF
x-help() {
echo "$helptxt"
}
x-book() {
asciidoctor \
-D "docs/$1" \
-o "index.html" \
"./adoc/$1/index.adoc"
}
x-site() {
asciidoctor \
-D "docs" \
-o "index.html" \
"./adoc/index.adoc"
x-book terminal-velocity
x-book shut-the-faq-up
x-book autodidactic
x-book bad-strimmer
x-book mormons-tale
}
x-watch() {
(
cd docs || return
browser-sync &
)
tmux rename-window "watching $(pwd)"
entr bash -c '
echo "Change detected. Rebuilding..."
./build site
' < <(find .)
sleep 1
}
# --------------------- completion and delegation --------------------
# The following provides bash completion with `complete -C build build`
# by deriving the names of the verbs for tab completion from those
# beginning with x- above. No other argument completion is provided.
while IFS= read -r line; do
[[ $line =~ ^declare\ -f\ x\- ]] || continue
commands+=("${line##declare -f x-}")
done < <(declare -F)
mapfile -t commands < \
<(LC_COLLATE=C sort < <(printf "%s\n" "${commands[@]}"))
if [[ -n $COMP_LINE ]]; then
line=${COMP_LINE#* }
for c in "${commands[@]}"; do
[[ ${c:0:${#line}} == "${line,,}" ]] && echo "$c"
done
exit
fi
if [[ -n "$1" ]]; then
declare action="$1"
shift
for c in "${commands[@]}"; do
declare cmd
cmd=$(command -v "x-$c")
if [[ $c == "$action" && -n "$cmd" ]]; then
"x-$action" "$@"
exit $?
fi
done
fi
x-site