-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.sh
77 lines (70 loc) · 1.82 KB
/
helper.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
# colors
COLOR_GRAY="\033[0;38;5;243m"
COLOR_BLUE="\033[0;34m"
COLOR_GREEN="\033[0;32m"
COLOR_RED="\033[0;31m"
COLOR_YELLOW="\033[0;33m"
COLOR_NONE="\033[0m"
# outputs
title() {
printf "\n%b[%b == %b]%b %b%b\n" "$COLOR_GRAY" "$COLOR_BLUE" "$COLOR_GRAY" "$COLOR_BLUE" "$1" "$COLOR_NONE"
}
subtitle() {
printf "\n%b[%b -- %b]%b %b%b\n" "$COLOR_GRAY" "$COLOR_BLUE" "$COLOR_GRAY" "$COLOR_BLUE" "$1" "$COLOR_NONE"
}
info() {
printf "%b[%b .. %b]%b %b\n" "$COLOR_GRAY" "$COLOR_BLUE" "$COLOR_GRAY" "$COLOR_NONE" "$1"
}
question() {
printf "\n%b[%b ?? %b]%b %b\n" "$COLOR_GRAY" "$COLOR_BLUE" "$COLOR_GRAY" "$COLOR_NONE" "$1"
}
success() {
printf "%b[%b OK %b]%b %b\n" "$COLOR_GRAY" "$COLOR_GREEN" "$COLOR_GRAY" "$COLOR_NONE" "$1"
}
warning() {
printf "%b[%bWARN%b]%b %b\n" "$COLOR_GRAY" "$COLOR_YELLOW" "$COLOR_GRAY" "$COLOR_NONE" "$1"
}
skip() {
printf "%b[%bSKIP%b]%b %b\n" "$COLOR_GRAY" "$COLOR_YELLOW" "$COLOR_GRAY" "$COLOR_NONE" "$1"
}
fail() {
printf "%b[%bFAIL%b]%b %b\n" "$COLOR_GRAY" "$COLOR_RED" "$COLOR_GRAY" "$COLOR_NONE" "$1"
exit 1
}
# check if not dry-run
is_active() {
[[ "$OPTION_DRYRUN" == "true" ]] && printf "%b!%b" "$COLOR_YELLOW" "$COLOR_NONE"
[[ "$OPTION_DRYRUN" != "true" ]]
}
# check OS
is_linux() {
[[ $(uname -s) == "Linux" ]]
}
is_macos() {
[[ $(uname -s) == "Darvin" ]]
}
# is_windows_wsl() {
# # TODO
# }
# get true/false as yes/no
get_yes_no() {
local yes="${COLOR_GREEN}Yes${COLOR_NONE}"
local no="${COLOR_RED}No${COLOR_NONE}"
if [[ "$1" == "true" ]]; then echo "$yes"; else echo "$no"; fi
}
# check if a command exists
is_command() {
command -v "$1" &>/dev/null
}
# ready to start
ask_to_start() {
question "Ready to start (y/n)?"
read -r -n 1 answer
printf "\r"
if [[ "$answer" != "y" && "$answer" != "Y" ]]; then
info "Bye"
exit 0
fi
info "$answer"
}