This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pkitty
executable file
·337 lines (302 loc) · 12.8 KB
/
pkitty
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/env bash
## ANSI Colors (FG & BG)
RED="$(printf '\033[31m')" GREEN="$(printf '\033[32m')" ORANGE="$(printf '\033[33m')" BLUE="$(printf '\033[34m')"
MAGENTA="$(printf '\033[35m')" CYAN="$(printf '\033[36m')" WHITE="$(printf '\033[37m')" BLACK="$(printf '\033[30m')"
REDBG="$(printf '\033[41m')" GREENBG="$(printf '\033[42m')" ORANGEBG="$(printf '\033[43m')" BLUEBG="$(printf '\033[44m')"
MAGENTABG="$(printf '\033[45m')" CYANBG="$(printf '\033[46m')" WHITEBG="$(printf '\033[47m')" BLACKBG="$(printf '\033[40m')"
DEFAULT_FG="$(printf '\033[39m')" DEFAULT_BG="$(printf '\033[49m')" BOLD="$(tput bold)" NORMAL="$(tput sgr0)"
## Directories
KITTY_DIR="$HOME/.config/kitty"
LIGHT_DIR="/usr/local/share/pretty-kitty/colors/light"
DARK_DIR="/usr/local/share/pretty-kitty/colors/dark"
FONTS_DIR="/usr/local/share/fonts/pretty-kitty"
## Banner
banner () {
clear
printf '\n%s' "
${ORANGE}☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴
${CYAN}██▓▒░⡷⠂${RED} 𝓟𝓻𝓮𝓽𝓽𝔂 𝓚𝓲𝓽𝓽𝔂 ${BLUE}🐈 ${CYAN}⠐⢾░▒▓██
${ORANGE}☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴☴
"
}
exit_on_signal_SIGINT () {
{ printf "\n\n%s\n" " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}Script interrupted" 2>&1; reload_settings; reset_color; }
exit 0
}
exit_on_signal_SIGTERM () {
{ printf "\n\n%s\n" " ${BOLD}${MAGENTA} ⚫ ${NORMAL} ${BLUE}Script terminated" 2>&1; reload_settings; reset_color; }
exit 0
}
trap exit_on_signal_SIGINT SIGINT
trap exit_on_signal_SIGTERM SIGTERM
## Reset terminal colors
reset_color() {
tput sgr0 # reset attributes
tput op # reset color
return
}
check_files () {
shopt -s nullglob dotglob
if [[ "$1" = light ]]; then
light=( "${LIGHT_DIR}"/*.conf )
printf "%d\n" ${#light[@]}
elif [[ "$1" = dark ]]; then
dark=( "${DARK_DIR}"/*.conf )
printf "%d\n" ${#dark[@]}
elif [[ "$1" = fonts ]]; then
fonts=( "${FONTS_DIR}"/*.ttf )
printf "%d\n" ${#fonts[@]}
fi
unset light dark fonts
return
}
total_light=$(check_files light)
total_dark=$(check_files dark)
total_fonts=$(check_files fonts)
## Reload Settings
reload_settings () {
printf '\n%s' " ${BOLD}${GREEN} ✔️ ${NORMAL} ${BLUE}Reloading Settings...";
kitty @ set-colors --all "$KITTY_DIR/colors.conf" > /dev/null
return
}
## Print Message
restart_kitty () {
printf '\n%s' " ${BOLD}${RED} ! ${NORMAL} ${BLUE}Please Restart Kitty";
return
}
invalid_option () {
printf '\n%s' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}Invalid Option, Try Again"
return
}
select_light () {
if ! cd "$LIGHT_DIR"; then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}${LIGHT_DIR} doesn't exist${BLUE}";
exit 1
fi
scheme=$( fzf )
printf '\n%s' " ${BOLD}${RED} ♥ ${NORMAL} ${BLUE}You selected: ${scheme##*/}"
if ! cp --force "${LIGHT_DIR}/${scheme}" "${KITTY_DIR}/colors.conf" &>/dev/null; then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}Failed to apply theme${BLUE}";
return 1
fi
printf '%s' "${scheme}" > "/tmp/kitty_theme_name.txt"
printf '%s' "light" > "/tmp/kitty_theme.txt"
{ reload_settings; reset_color; exit; }
}
select_dark () {
if ! cd "$DARK_DIR"; then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}${DARK_DIR} doesn't exist${BLUE}";
exit 1
fi
scheme=$( fzf )
printf '\n%s' " ${BOLD}${RED} ♥ ${NORMAL} ${BLUE}You selected: ${scheme##*/}"
if ! cp --force "${DARK_DIR}/${scheme}" "${KITTY_DIR}/colors.conf" &>/dev/null; then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}Failed to apply theme${BLUE}";
return 1
fi
printf '%s' "${scheme}" > "/tmp/kitty_theme_name.txt"
printf '%s' "dark" > "/tmp/kitty_theme.txt"
{ reload_settings; reset_color; exit; }
}
apply_font_family () {
if ! grep -Ewq 'font_family' "${KITTY_DIR}/kitty.conf"; then
banner
printf '\n%s\n' " ${BOLD}${RED} ➕ ${NORMAL} ${BLUE}Adding font_family option to config..."
printf '\n%s' "font_family" >> "${KITTY_DIR}/kitty.conf"
sleep 1;
fi
if ! cd "$FONTS_DIR"; then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}${FONTS_DIR} doesn't exist${BLUE}";
exit 1
fi
font_ttf=$( fzf )
font_name=$(fc-list | grep -i $font_ttf | head -n 1 | cut -d':' -f2)
if [ "$font_name" == "" ];then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}Failed to apply font${BLUE}";
return 1
fi
printf '\n%s' " ${BOLD}${RED} ♥ ${NORMAL} ${BLUE}Changing font to: $font_name"
sed -ie "s/.*font_family.*/font_family $font_name/g" "$KITTY_DIR/kitty.conf"
{ restart_kitty; reload_settings; exit; }
}
apply_font_size () {
if ! grep -Ewq 'font_size' "${KITTY_DIR}/kitty.conf"; then
banner
printf '\n%s\n' " ${BOLD}${RED} ➕ ${NORMAL} ${BLUE}Adding font_size option to config..."
printf '\n%s' "font_size" >> "${KITTY_DIR}/kitty.conf"
sleep 1;
fi
printf "\n"
read -r -p " ${BLACKBG}${BOLD}${WHITE} Enter Font Size (Default is 10) ${WHITEBG}${RED} ► ${NORMAL} " font_size;
printf '\n%s' " ${BOLD}${RED} ♥ ${NORMAL} ${BLUE}Setting size to: $font_size"
sed -ie "s/.*font_size.*/font_size ${font_size:-10}/g" "$KITTY_DIR/kitty.conf"
{ restart_kitty; reload_settings; exit; }
}
random_light () {
random_scheme="$(find "$LIGHT_DIR" -type f -name "*.conf" | shuf -n 1)"
printf '\n%s' " ${BOLD}${GREEN} ✔️ ${NORMAL} ${BLUE}Theme Set To: ${random_scheme##*/}"
if ! cp --force "${random_scheme}" "${KITTY_DIR}/colors.conf" &>/dev/null; then
printf '%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}Failed to apply theme!" >&2
return 1
fi
printf %s "${random_scheme##*/}" > "/tmp/kitty_theme_name.txt"
echo "${scheme}"
printf '%s' "light" > "/tmp/kitty_theme.txt"
{ reload_settings; reset_color; exit; }
}
random_dark () {
random_scheme="$(find "$DARK_DIR" -type f -name "*.conf" | shuf -n 1)"
printf '\n%s' " ${BOLD}${GREEN} ✔️ ${NORMAL} ${BLUE}Theme Set To: ${random_scheme##*/}"
if ! cp --force "${random_scheme}" "${KITTY_DIR}/colors.conf" &>/dev/null; then
printf '%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}Failed to apply theme!" >&2
return 1
fi
printf %s "${random_scheme##*/}" > "/tmp/kitty_theme_name.txt"
printf '%s' "dark" > "/tmp/kitty_theme.txt"
{ reload_settings; reset_color; exit; }
}
toggle_theme () {
if grep -Ewq 'dark' "/tmp/kitty_theme.txt"; then
random_light
else
random_dark
fi
}
import_files () {
printf '\n%s\n' " ${WHITEBG}${BOLD}${BLACK} L ${DEFAULT_BG}${NORMAL} ${BLUE}Local File (Enter path to file)
${BLACKBG}${BOLD}${WHITE} I ${DEFAULT_BG}${NORMAL} ${BLUE}Internet File (Enter File URL)"
{ printf "\n"; read -r -n 1 -p " ${BLACKBG}${BOLD}${WHITE} Select Option ${WHITEBG}${RED} ► ${DEFAULT_BG}${NORMAL}" option; printf "\n"; }
temp_file=$(mktemp /tmp/kitty_XXXXXXXXXX.conf)
if [[ "$option" =~ ^[l/L/i/I]$ ]]; then
if [[ "$option" =~ ^[l/L]$ ]]; then
read -r -e -p " ${BLACKBG}${BOLD}${WHITE} Enter Path To Color-scheme ${WHITEBG}${RED} ► ${DEFAULT_BG}${NORMAL} " file_path;
cat "$file_path" > "$KITTY_DIR/colors.conf"
{ reload_settings; reset_color; exit; }
elif [[ "$option" =~ ^[i/I]$ ]]; then
read -r -p " ${BLACKBG}${BOLD}${WHITE} Enter Color-scheme URL ${WHITEBG}${RED} ► ${DEFAULT_BG}${NORMAL} " file_link;
wget -o /tmp/log -O "$temp_file" "$file_link"
cat "$temp_file" > "$KITTY_DIR/colors.conf"
{ reload_settings; reset_color; exit; }
fi
else
invalid_option
{ sleep 2; banner; import_files; }
fi
}
update_pkitty () {
banner;
printf '\n%s' " ${BOLD}${RED} ! ${NORMAL} ${BLUE}UPDATING..."
printf '\n%s' " ${BLUE}"
if [[ ! -d $HOME/pretty-kitty ]]; then
git clone https://github.com/zim0369/pretty-kitty "$HOME/pretty-kitty"
if ! cd "$HOME/pretty-kitty"; then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}${HOME}/pretty-kitty doesn't exist${BLUE}";
exit 1
fi
else
printf '\n%s' " ${BOLD}${RED} ! ${NORMAL} ${BLUE}Directory Exists..."
if ! cd "$HOME/pretty-kitty"; then
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}${HOME}/pretty-kitty doesn't exist${BLUE}";
exit 1
fi
git pull
fi
sh install
{ reload_settings; reset_color; exit; }
}
interface() {
until [[ "$REPLY" =~ ^[q/Q]$ ]]; do
banner
printf '\n%s' "
${BLACKBG}${BOLD}${WHITE} D ${DEFAULT_BG}${NORMAL}${BLUE} Select Dark Theme(${total_dark})
${WHITEBG}${BOLD}${BLACK} L ${DEFAULT_BG}${NORMAL}${BLUE} Select Light Theme(${total_light})
${BLACKBG}${BOLD}${WHITE} F ${DEFAULT_BG}${NORMAL}${BLUE} Font Family(${total_fonts})
${WHITEBG}${BOLD}${BLACK} S ${DEFAULT_BG}${NORMAL}${BLUE} Font Size
${BLACKBG}${BOLD}${WHITE} U ${DEFAULT_BG}${NORMAL}${BLUE} Update pkitty
${WHITEBG}${BOLD}${BLACK} I ${DEFAULT_BG}${NORMAL}${BLUE} Import Files
${BLACKBG}${BOLD}${WHITE} Q ${DEFAULT_BG}${NORMAL}${BLUE} Quit
"
{ printf "\n"; read -r -n 1 -p "${BOLD} ${BLACKBG}${WHITE} Select Option ${WHITEBG}${RED} ► ${DEFAULT_BG}${NORMAL}"; printf "\n"; banner; }
if [[ "$REPLY" =~ ^[d/D/l/L/f/F/s/S/u/U/i/I/q/Q]$ ]]; then #validate input
if [[ "$REPLY" =~ ^[d/D]$ ]]; then
select_dark
elif [[ "$REPLY" =~ ^[l/L]$ ]]; then
select_light
elif [[ "$REPLY" =~ ^[f/F]$ ]]; then
apply_font_family
elif [[ "$REPLY" =~ ^[s/S]$ ]]; then
apply_font_size
elif [[ "$REPLY" =~ ^[i/I]$ ]]; then
import_files
elif [[ "$REPLY" =~ ^[u/U]$ ]]; then
update_pkitty
fi
else
# invalid_option
sleep 2
fi
done
{ printf '\n%s\n' " ${BOLD}${MAGENTA} ⚫ ${NORMAL} ${BLUE}Bye Bye, Have A Nice Day!"; reload_settings; reset_color; exit 0; }
}
show_help() {
theme=`cat /tmp/kitty_theme_name.txt`
printf '\n%s\n' "Current Theme: '${RED}${theme}${DEFAULT_FG}'";
cat << EOF
${DEFAULT_FG}
USAGE: ${0##*/} [OPTIONS]
OPTIONS:
${BOLD}${GREEN} h, -h${NORMAL}${DEFAULT_FG}, --help Show this help message
${BOLD}${GREEN} d, -d${NORMAL}${DEFAULT_FG}, --dark Select a random dark theme
${BOLD}${GREEN} l, -l${NORMAL}${DEFAULT_FG}, --light Select a random light theme
${BOLD}${GREEN} t, -t${NORMAL}${DEFAULT_FG}, --toggle Toggle theme
${BOLD}${RED} --remove${NORMAL}${DEFAULT_FG} Uninstall pkitty
EOF
}
main() {
if ! [ -s "${KITTY_DIR}/kitty.conf" ]; then
printf '\n%s' " ${BOLD}${MAGENTA} ⚫ ${NORMAL} ${BLUE}Cannot find kitty configuration: '${KITTY_DIR}/kitty.conf'${BLUE}";
printf '\n%s' " ${BOLD}${MAGENTA} ⚫ ${NORMAL} ${BLUE}Creating one for you...${BLUE}";
cp -r /usr/local/share/pretty-kitty/kitty.conf "$KITTY_DIR"
{ restart_kitty; reset_color; exit; }
fi
if [ ! -f "${KITTY_DIR}/colors.conf" ]; then
printf '\n%s' " ${BOLD}${MAGENTA} ⚫ ${NORMAL} ${BLUE}Cannot find '${KITTY_DIR}/colors.conf'${BLUE}";
printf '\n%s' " ${BOLD}${MAGENTA} ⚫ ${NORMAL} ${BLUE}Creating one for you...${BLUE}";
touch "${KITTY_DIR}/colors.conf"
{ restart_kitty; reset_color; exit; }
fi
if ! grep --quiet 'colors\.conf' "${KITTY_DIR}/kitty.conf"; then
banner
printf '\n%s' " ${BOLD}${RED} ➕ ${NORMAL} ${BLUE}Adding colors.conf import to kitty config..."
printf '\n%s' "include ${KITTY_DIR}/colors.conf" >> "${KITTY_DIR}/kitty.conf"
{ restart_kitty; reset_color; exit; }
fi
# Check arguments
if [ "$1" == "h" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
show_help
exit 0
elif [ "$1" == "d" ] || [ "$1" == "-d" ] || [ "$1" == "--dark" ]; then
random_dark
exit 0
elif [ "$1" == "l" ] || [ "$1" == "-l" ] || [ "$1" == "--light" ]; then
random_light
exit 0
elif [ "$1" == "t" ] || [ "$1" == "-t" ] || [ "$1" == "--toggle" ]; then
toggle_theme
exit 0
elif [ "$1" == "--uninstall" ]; then
sh /usr/local/share/pretty-kitty/uninstall
exit 0
elif [ $# -eq 0 ]; then
interface
exit 0
else
printf '\n%s\n' " ${BOLD}${RED} ❌ ${NORMAL} ${BLUE}BAD COMMAND...${BLUE}";
sleep 1;
banner
show_help
exit 0
fi
return 0
}
main "${@}"