-
Notifications
You must be signed in to change notification settings - Fork 2
/
lib.sh
85 lines (74 loc) · 1.45 KB
/
lib.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
83
84
85
#!/bin/sh
# source guard
if [ -z "${LIB_SH}" ]; then
echo "This is a library. Don't execute it directly."
exit 1
fi
normal="$(tput sgr0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
warning() {
echo "${N}: ${yellow}$*${normal}" 1>&2
}
bar() {
echo "================================================================================"
}
say() {
echo -e "${N}: $*${normal}" 1>&2
}
sayn() {
echo -ne "$*${normal}" 1>&2
}
quote() {
for s in "$@"; do
printf "${sep}%q" "${s}"
sep=" "
done
}
quoteline() {
local sep=""
while read -r line; do
echo -n "${sep}"
quote "${line}"
done
}
nquote() {
local sep=""
for s in "$@"; do
local e="$(quote "${s}")"
if [ "${s}" != "${e}" ]; then
echo -n "${sep}'${s}'"
else
echo -n "${sep}${s}"
fi
sep=" "
done
}
nquoteline() {
local sep=" "
while read -r line; do
echo -n "${sep}"
nquote "${line}"
sep=" "
done
}
run_editor() {
local file="$1"
local we=""
for e in sensible-editor editor ${EDITOR} vim vi nano pico; do
we="$(which "${e}")"
if [ -n "${we}" ]; then
"${we}" "${file}"
fi
return 0
done
echo "Could not find an editor"
return 1
}
alltests() {
basename -s .base.cmd *.base.cmd | nquoteline
}
alltestvariants() {
basename -s .cmd *.cmd | nquoteline
}