-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_functions.sh
More file actions
91 lines (79 loc) · 1.48 KB
/
_functions.sh
File metadata and controls
91 lines (79 loc) · 1.48 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
#!/usr/bin/env sh
# shellcheck disable=2034
if [ ! -t 0 ]; then
__fmt() { :; }
else
__fmt() {
tput "$@"
}
fi
PRINTED=false
BOLD=$(__fmt bold)
RED=$(__fmt setaf 1)
GREEN=$(__fmt setaf 2)
YELLOW=$(__fmt setaf 3)
BLUE=$(__fmt setaf 4)
MAGENTA=$(__fmt setaf 5)
CYAN=$(__fmt setaf 6)
WHITE=$(__fmt setaf 7)
RESET=$(__fmt sgr0)
rawprint() {
command printf "$@"
}
# shellcheck disable=SC2059
debug() {
if [ "${DEBUG_BOOTSTRAP:-0}" = 1 ]; then
msg="$1"
shift
rawprint -- "${BOLD}${BLUE}[DEBUG]${RESET} $msg\n" "$@"
PRINTED=true
fi
}
# shellcheck disable=SC2059
info() {
msg="$1"
shift
rawprint -- "${BOLD}${GREEN}[INFO]${RESET} $msg\n" "$@"
PRINTED=true
}
# shellcheck disable=SC2059
warn() {
msg="$1"
shift
rawprint -- "${BOLD}${YELLOW}[WARN]${RESET} $msg\n" "$@" 1>&2
PRINTED=true
}
# shellcheck disable=SC2059
error() {
msg="$1"
shift
rawprint -- "${BOLD}${MAGENTA}[ERROR]${RESET} $msg\n" "$@" 1>&2
PRINTED=true
}
# shellcheck disable=SC2059
abort() {
msg="$1"
shift
rawprint -- "${BOLD}${RED}[FATAL]${RESET} $msg\n" "$@" 1>&2
exit 1
}
printf() {
info "$@"
}
linebreak() {
if [ "$PRINTED" = true ]
then
rawprint "\n"
fi
PRINTED=false
}
#-BEGIN:${SCRIPTDIR}/_functions.d
for funcdef in "${SCRIPTDIR}/_functions.d"/*
do
if [ -f "$funcdef" ]
then
# shellcheck disable=1090
. "$funcdef"
fi
done
#-END:${SCRIPTDIR}/_functions.d