-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_helpers.sh
78 lines (65 loc) · 1.35 KB
/
output_helpers.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
#!/usr/bin/env bash
#
# Author: Stanislav Zhuk <[email protected]>
#
function primary() {
echo -e "\033[0;34m${1}\033[0m"
}
function secondary() {
echo -e "\033[0;35m${1}\033[0m"
}
function success() {
echo -e "\033[0;32m${1}\033[0m"
}
function warning() {
echo -e "\033[0;33m${1}\033[0m"
}
function info() {
echo -e "\033[0;36m${1}\033[0m"
}
function danger() {
echo -e "\033[0;31m${1}\033[0m"
}
function failure() {
echo >&2 -e "\033[0;31m${1}\033[0m"
if [[ $(type -t usage) == function ]]; then
echo
usage
fi
exit 1
}
# shellcheck disable=SC2120
function confirm() {
local message="${1:-Are you sure?}"
local yes_no="${2:-yes}"
echo
if [[ "${yes_no}" == "yes" ]]; then
read -rp "${message} (Y/n): " REPLY
else
read -rp "${message} (y/N): " REPLY
if [[ -z "${REPLY}" ]]; then
return 1
fi
fi
echo
# convert to lowercase
REPLY="${REPLY,,}"
if [[ -z "${REPLY}" || "${REPLY}" == "y" || "${REPLY}" == "yes" ]]; then
return 0
else
return 1
fi
}
function script_intro() {
echo -e "${script_name:-Name} \033[0;32m${script_version:-Version}\033[0m\n"
}
export -f \
primary \
secondary \
success \
warning \
info \
danger \
failure \
confirm \
script_intro