-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitflux-io
87 lines (74 loc) · 1.93 KB
/
gitflux-io
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
#!/usr/bin/env bash
# all those unicode characters may not show in git-bash, f*** that.
io_sign_v="✔"
io_sign_x="✘"
io_sign_i="ℹ"
io_sign_star="★"
io_sign_arrow="➤"
io_log() {
io_print " " "$@"
}
io_log_ok() {
io_print "$(f_fg_green " $io_sign_v ")" "$@"
}
io_log_info() {
io_print "$(f_fg_blue " $io_sign_i ")" "$@"
}
io_log_banner() {
io_print "$(f_fg_blue " $io_sign_star $io_sign_star $io_sign_star ")" "$(f_bold "$1")" 2 "$(f_fg_blue " $io_sign_star $io_sign_star $io_sign_star ")"
}
io_log_warn() {
io_print "$(f_fg_yellow " $io_sign_x ")" "$@" >&2
}
io_status_fatal() {
die "$(io_print "$(f_fg_red " $io_sign_x ")" "$@")
" >&2
}
io_status_logger() {
if (( $1 == 0 )); then
io_log_ok "$2" 1
else
io_status_fatal "$3" 1
fi
}
io_prompt() {
local question="$1"
local default_suggestion="$2"
if [[ -n $default_suggestion ]]; then
question="${question} [$default_suggestion]"
fi
# use -p instead of sending the question to stdout, as this function will probably be
# called in a $(subshell), so printing to stdout won't work as expected
read -r -p "$(printf "$(f_fg_yellow " $io_sign_arrow ")%s " "$question")" answer
echo "${answer:-$default_suggestion}"
}
io_prompt_pass() {
local question="$1"
# use -p instead of sending the question to stdout, as this function will probably be
# called in a $(subshell), so printing to stdout won't work as expected
read -r -s -p "$(printf "$(f_fg_yellow " $io_sign_arrow ")%s " "$question")" answer
echo "$answer"
}
io_confirm() {
local question="$1"
local exit_message="$2";
local answer
answer=$(io_prompt "$question (y/n)")
if [[ $answer != "y" ]]; then
io_status_fatal "$exit_message" 1
fi
}
io_print() {
local margin="$1"
local body="$2"
local indent_level=$3
local end_margin="$4"
local n
local indent=""
if [[ $indent_level =~ [123] ]]; then
for (( n=indent_level; n > 0; n-- )); do
indent=" $indent"
done
fi
echo "$indent$margin$body$end_margin"
}