-
Notifications
You must be signed in to change notification settings - Fork 19
/
interactive-utils.sh
77 lines (64 loc) · 1.33 KB
/
interactive-utils.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
#!/usr/bin/env bash
GREEN='\033[0;32m'
RED='\033[0;31m'
GRAY='\033[0;30m'
NO_COLOR='\033[0m'
CAT=$(if [[ -x "$(command -v bat)" ]]; then echo "bat"; else echo "cat"; fi)
function heading() {
echo
echo -e "${RED}# ${1}${NO_COLOR}"
echo -e "${RED}========================================${NO_COLOR}"
}
function subHeading() {
echo
echo -e "${GREEN}# ${1}${NO_COLOR}"
echo
pressKeyToContinue
}
function message() {
echo
echo -e "${GREEN}${1}${NO_COLOR}"
echo
pressKeyToContinue
}
function pressKeyToContinue() {
if [[ "${PRINT_ONLY}" != "true" ]]; then
read -n 1 -s -r -p "Press any key to continue"
removeOutputLine
fi
}
function confirm() {
# shellcheck disable=SC2145
# - the line break between args is intended here!
printf "%s\n" "${@:-Are you sure? [y/N]} "
read -r response
case "$response" in
[yY][eE][sS] | [yY])
true
;;
*)
false
;;
esac
}
function removeOutputLine() {
echo -en "\r\033[K"
}
function printAndRun() {
echo "$ ${1}"
run "${1}"
}
function run() {
if [[ "${PRINT_ONLY}" != "true" ]]; then
eval ${1} || true
fi
}
function printFile() {
${CAT} ${1}
pressKeyToContinue
}
function kubectlSilent() {
if [[ "${PRINT_ONLY}" != "true" ]]; then
kubectl "$@" > /dev/null 2>&1 || true
fi
}