-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals
132 lines (121 loc) · 2.9 KB
/
globals
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
#!/bin/bash
# SPDX-FileCopyrightText: 2023 sudorook <daemon@nullcodon.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
show_error() {
local red=$'\033[0;91m'
local nc=$'\033[0m'
if [[ "${1:--e}" =~ ^(-e|-n)$ ]]; then
echo "${1:--e}" "${red}${*:2}${nc}" 1>&2
else
echo -e "${red}${*}${nc}" 1>&2
fi
}
export -f show_error
show_info() {
local green=$'\033[0;92m'
local nc=$'\033[0m'
if [[ "${1:--e}" =~ ^(-e|-n)$ ]]; then
echo "${1:--e}" "${green}${*:2}${nc}"
else
echo -e "${green}${*}${nc}"
fi
}
export -f show_info
show_warning() {
local yellow=$'\033[0;93m'
local nc=$'\033[0m'
if [[ "${1:--e}" =~ ^(-e|-n)$ ]]; then
echo "${1:--e}" "${yellow}${*:2}${nc}"
else
echo -e "${yellow}${*}${nc}"
fi
}
export -f show_warning
show_question() {
local blue=$'\033[0;94m'
local nc=$'\033[0m'
if [[ "${1:--e}" =~ ^(-e|-n)$ ]]; then
echo "${1:--e}" "${blue}${*:2}${nc}"
else
echo -e "${blue}${*}${nc}"
fi
}
export -f show_question
ask_question() {
local blue=$'\033[0;94m'
local nc=$'\033[0m'
local var
read -r -p "${blue}$*${nc} " var
echo "${var}"
}
export -f ask_question
ask_secret() {
local blue=$'\033[0;94m'
local nc=$'\033[0m'
local var
stty -echo echonl
read -r -p "${blue}$*${nc} " var
stty echo -echonl
echo "${var}"
}
export -f ask_secret
show_success() {
local purple=$'\033[0;95m'
local nc=$'\033[0m'
if [[ "${1:--e}" =~ ^(-e|-n)$ ]]; then
echo "${1:--e}" "${purple}${*:2}${nc}"
else
echo -e "${purple}${*}${nc}"
fi
}
export -f show_success
show_header() {
local cyan=$'\033[0;96m'
local nc=$'\033[0m'
if [[ "${1:--e}" =~ ^(-e|-n)$ ]]; then
echo "${1:--e}" "${cyan}${*:2}${nc}"
else
echo -e "${cyan}${*}${nc}"
fi
}
export -f show_header
show_listitem() {
local white=$'\033[0;97m'
local nc=$'\033[0m'
if [[ "${1:--e}" =~ ^(-e|-n)$ ]]; then
echo "${1:--e}" "${white}${*:2}${nc}"
else
echo -e "${white}${*}${nc}"
fi
}
export -f show_listitem
check_command() {
local package
local missing=()
for package in "${@}"; do
if ! command -v "${package}" > /dev/null; then
missing+=("${package}")
fi
done
if [ ${#missing[@]} -eq 0 ]; then
return 0
else
show_error "MISSING: ${missing[*]@Q} not installed."
return 1
fi
}
export -f check_command