-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathinteraction_fn.sh
More file actions
178 lines (156 loc) · 4.47 KB
/
Copy pathinteraction_fn.sh
File metadata and controls
178 lines (156 loc) · 4.47 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
# initial user interaction functions...
# color definition (ascii)
red="\e[1;31m"
green="\e[1;32m"
yellow="\e[1;33m"
blue="\e[1;34m"
magenta="\e[1;1;35m"
cyan="\e[1;36m"
orange="\x1b[38;5;214m"
end="\e[1;0m"
# cache dir
dir="$(dirname "$(realpath "$0")")"
# creating a cache directory..
cache_dir="$dir/.cache"
cache_file="$cache_dir/user-cache"
shell_cache="$cache_dir/shell"
[[ ! -d "$cache_dir" ]] && mkdir -p "$cache_dir"
#______( starts functions here )______#
fn_welcome() {
gum style \
--foreground "#00FFFF" \
--border-foreground "#00FFFF" \
--border rounded \
--align center \
--width 90 \
--margin "1 2" \
--padding "1 2" \
'Welcome to the' 'Hyprland installation script by,' '
_____ __ __ __ _ __ _ _
/ ___/ / /_ ___ / // / / | / /(_)____ (_)____ _
\__ \ / __ \ / _ \ / // / / |/ // // __ \ / // __ `/
___/ // / / // __// // / / /| // // / / / / // /_/ /
/____//_/ /_/ \___//_//_/ /_/ |_//_//_/ /_/__/ / \__,_/
/___/
'
}
fn_ask() {
gum confirm "$1" \
--prompt.foreground "#ff8700" \
--affirmative "$2" \
--selected.background "#00FFFF" \
--selected.foreground "#000" \
--negative "$3"
}
fn_exit() {
gum spin --spinner line \
--spinner.foreground "#FF0000" \
--title "$1" \
--title.foreground "#FF0000" -- \
sleep 1
exit 1
}
# only for asking the prompts...
fn_ask_prompts() {
# Generate human-readable labels
local -A label_to_key
local labels=()
for key in "${!options[@]}"; do
local label=$(echo "$key" | tr '_' ' ' | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1')
label_to_key["$label"]="$key"
labels+=("$label")
done
# Use gum to capture selected options
local selected
selected=$(gum choose \
--header "Select using the 'space' bar" \
--no-limit \
--cursor.foreground "#00FFFF" \
--item.foreground "#fff" \
--selected.foreground "#00FF00" \
"${labels[@]}")
# Reset all options to 'N' by default
for key in "${!options[@]}"; do
options[$key]="N"
done
# Set the selected options to 'Y'
while IFS= read -r label; do
if [[ -n "$label" ]]; then
local key="${label_to_key[$label]}"
options[$key]="Y"
fi
done <<< "$selected"
# Update the cache file with the new values
> "$cache_file"
for key in "${!options[@]}"; do
echo "$key='${options[$key]}'" >> "$cache_file"
done
}
# only for asking shell prompts...
fn_shell() {
# Generate human-readable labels
local -A label_to_key
local labels=()
for key in "${!shell_options[@]}"; do
local label=$(echo "$key" | tr '_' ' ' | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1')
label_to_key["$label"]="$key"
labels+=("$label")
done
# Use gum to capture selected options
local selected
selected=$(gum choose \
--header "Choose only one. Press 'ENTER'" \
--limit=1 \
--cursor.foreground "#00FFFF" \
--item.foreground "#fff" \
--selected.foreground "#00FF00" \
"${labels[@]}")
# Reset all options to 'N' by default
for key in "${!shell_options[@]}"; do
shell_options[$key]="N"
done
# Set the selected options to 'Y'
while IFS= read -r label; do
if [[ -n "$label" ]]; then
local key="${label_to_key[$label]}"
shell_options[$key]="Y"
fi
done <<< "$selected"
# Update the cache file with the new values
> "$shell_cache"
for key in "${!shell_options[@]}"; do
echo "$key='${shell_options[$key]}'" >> "$shell_cache"
done
}
msg() {
local actn="$1"
local msg="$2"
case $actn in
act)
printf "${green}=>${end} $msg\n"
;;
ask)
printf "${orange}??${end} $msg\n"
;;
dn)
printf "${cyan}::${end} $msg\n\n"
;;
att)
printf "${yellow}!!${end} $msg\n"
;;
nt)
printf "${blue}\$\$${end} $msg\n"
;;
skp)
printf "${magenta}[ SKIP ]${end} $msg\n"
;;
err)
printf "${red}>< Ohh sheet! an error..${end}\n $msg\n"
sleep 1
;;
*)
printf "$msg\n"
;;
esac
}