-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettheme.sh
executable file
·350 lines (316 loc) · 16.4 KB
/
settheme.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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/env bash
# TODO:
# add support to compile dmenu
# check if colorscheme name file exist(update it)
# this will automatically remove and put the new one in place(/tmp/vim-colorschemes)
# . ~/.cache/temp/sh_files/vcolors.sh --gen # this will executes the script as this script process
# change colorscheme for terminal
#. ~/.cache/temp/sh_files/vcolors.sh -c # this will executes the script as this script process
#echo "${SELECTED_THEME_NAME}"
alacritty_theme_path="/home/$(logname)/.config/alacritty/alacritty_themes"
alacritty_config="/home/$(logname)/.config/alacritty"
termite_theme_path="/home/$(logname)/.config/termite/termite_themes"
termite_config="/home/$(logname)/.config/termite"
xresources_theme_path="/home/$(logname)/.config/xresources_colors/"
dunst_config="/home/$(logname)/.config/dunst/dunstrc"
rofi_config="/home/$(logname)/.config/rofi/config.rasi"
bspwm_config="/home/$(logname)/.config/bspwm/bspwmrc"
dmenu_config="/home/$(logname)/Downloads/git-materials/dmenu_mybuild/config.h"
zathura_config="/home/$(logname)/.config/zathura/zathurarc"
PS3="Select the file: "
selected_theme=""
function change_colorscheme_terminal() {
# change colorscheme for n/vim
. vcolors.sh -c # this will executes the script as this script process
selected_theme="${SELECTED_THEME_NAME}"
# echo "${selected_theme}"
# change colorscheme for TERMINAL
theme_files_count=0
if [ "$TERMINAL" = "alacritty" ]; then
theme_files=($(basename -a $(find "${alacritty_theme_path}" -type f -iname "*${selected_theme}*") 2>/dev/null))
theme_files_count="${#theme_files[@]}"
if [ ${theme_files_count} -gt 1 ]; then
echo "Found more than with this colorscheme"
if [ -n $(echo "${PATH}" | grep -io fzf) ]; then
selected_file=$(echo "${theme_files[@]}" | sed -e 's/ /\n/g' | fzf --prompt "Select file:" --border sharp --height 25%)
else
select selected_file in "${theme_files[@]}"; do
echo "you selected ${selected_file}"
break
done
fi
else
selected_file="${theme_files}"
fi
if [ -n "${selected_file}" ]; then
if [ -f "${alacritty_theme_path}/${selected_file}" ]; then
echo "Changing colorscheme for alacritty to ${selected_file}"
cat "${alacritty_config}/base.yml" "${alacritty_theme_path}/${selected_file}" > "${alacritty_config}/alacritty.yml"
echo "Changed successfully"
else
echo "Selected file not found, or not selected an option"
fi
else
echo "Selection not found in the folder ${alacritty_theme_path}"
fi
# configuration for termite is still left
elif [ "$TERMINAL" = "termite" ]; then
theme_files=($(basename -a $(find "${termite_theme_path}" -type f -iname "*${selected_theme}*") 2>/dev/null))
theme_files_count="${#theme_files[@]}"
if [ ${theme_files_count} -gt 1 ]; then
echo "Found more than with this colorscheme"
if [ -n $(echo "${PATH}" | grep -io fzf) ]; then
selected_file=$(echo "${theme_files[@]}" | sed -e 's/ /\n/g' | fzf --prompt "Select file:" --border sharp --height 25%)
else
select selected_file in "${theme_files[@]}"; do
echo "you selected ${selected_file}"
break
done
fi
else
selected_file="${theme_files}"
fi
if [ -n "${selected_file}" ]; then
if [ -f "${termite_theme_path}/${selected_file}" ]; then
echo "Changing colorscheme ${selected_file}"
cat "${termite_config}/base.yml" "${termite_theme_path}/${selected_file}" > "${termite_config}/test_termite.yml"
echo "Changed successfully"
else
echo "Selected file not found, or not selected an option"
fi
else
echo "Selection not found in the folder ${termite_theme_path}"
fi
else
echo "$TERMINAL not found"
fi
}
function change_colorscheme_xresources() {
# this will change the colors for Xresources and all other tools which are dependent on it
# like sxiv and my polybar build
theme_files=($(basename -a $(find "${xresources_theme_path}" -type f -iname "*${selected_theme}*") 2>/dev/null))
theme_files_count="${#theme_files[@]}"
if [ ${theme_files_count} -gt 1 ]; then
echo "Found more than with this colorscheme"
if [ -n "$(echo ${PATH} | grep -io fzf)" ]; then
selected_file=$(echo "${theme_files[@]}" | sed -e 's/ /\n/g' | fzf --prompt "Select file:" --border sharp --height 25%)
else
select selected_file in "${theme_files[@]}"; do
echo "you selected ${selected_file}"
break
done
fi
else
selected_file="${theme_files}"
fi
if [ -n "${selected_file}" ]; then
if [ -f "${xresources_theme_path}/${selected_file}" ]; then
echo "Selected file is: ${selected_file}"
echo "Changing colorscheme"
cat "${xresources_theme_path}"/"${selected_file}" "${xresources_theme_path}/base.Xresources" > /home/$(logname)/.Xresources
xrdb ~/.Xresources # get and set content
echo "Changed successfully"
else
echo "Selected file not found, or not selected an option"
fi
else
echo "Selection not found in the folder ${termite_theme_path}"
fi
}
function change_colorscheme_dunst() {
# change in dunstrc color file, # changing only for normal_urgency(which is most used)
# awk -v color="$background_xresources" -i inplace -e '/background/{c++;if(c==2){sub("background.*[#a-fA-F0-9]+", "background = \"color");c=0}}1' dunstrc
# don't understand what's wrong with above one(awk's), it's just not expanding the awk variable color for substitution
# range based sed, from urgency_normal till newline is encountered (format /rangestart/,/rangestop/s/search/replace/)
sed -i -E "/urgency_normal/,/^\s*$/s/(^\s*background\s*=\s*)\".+\"/\1\"${background_xresources}\"/" "${dunst_config}"
sed -i -E "/urgency_normal/,/^\s*$/s/(^\s*foreground\s*=\s*)\".+\"/\1\"${foreground_xresources}\"/" "${dunst_config}"
# from line 0 to first frame_color, and then replace, // means
sed -i -e "0,/\(^\s*frame_color\s*=\s*\)\".\+\"/s//\1\"${color7}\"/" "${dunst_config}"
# restart dunst
[ -n "$(pidof dunst)" ] && kill "$(pidof dunst)" && dunst 2>/dev/null &
sleep 0.5;
notify-send -t 3000 "Dunst Reloaded"
# print dunst changed color output, if verbose
if [ -n "$1" ]; then
printf "\n%s\n\n" "Colors for dunst on urgency_normal are: "
printf "%s\n" "$(sed -n -E "/urgency_normal/,/^\s*$/s/(^\s*background\s*=\s*\".+\")/\1/p" "${dunst_config}")"
printf "%s\n" "$(sed -n -E "/urgency_normal/,/^\s*$/s/(^\s*foreground\s*=\s*\".+\")/\1/p" "${dunst_config}")"
printf "%s\n\n" "$(sed -n -e "0,/\(^\s*frame_color\s*=\s*\".\+\"\)/s//\1/p" "${dunst_config}")"
else
echo "Colors for dunst changed"
fi
}
function change_colorscheme_rofi() {
# sed -n -e "s/\(^\s*background-color\s*:\s*\)[#[:alnum:]]\+;/\1#282828/p" config.rasi
sed -i -e "s/\(^\s*background-color\s*:\s*\)[#[:alnum:]]\+;/\1${background_xresources};/" "${rofi_config}"
sed -i -e "s/\(^\s*text-color\s*:\s*\)[#[:alnum:]]\+;/\1${foreground_xresources};/" "${rofi_config}"
sed -i -e "s/\(^\s*selbg\s*:\s*\)[#[:alnum:]]\+;/\1${color8};/" "${rofi_config}"
sed -i -e "s/\(^\s*actbg\s*:\s*\)[#[:alnum:]]\+;/\1${color2};/" "${rofi_config}"
sed -i -e "s/\(^\s*urgbg\s*:\s*\)[#[:alnum:]]\+;/\1${color1};/" "${rofi_config}"
sed -i -e "s/\(^\s*winbg\s*:\s*\)[#[:alnum:]]\+;/\1${background_xresources};/" "${rofi_config}"
# print rofi changed color ouptut
if [ -n "$1" ]; then
printf "\n%s\n\n" "Colors for rofi are: "
printf "%s\n" "$(sed -n -e "/^\s*background-color\s*:\s*[#[:alnum:]]\+;/p" "${rofi_config}")"
printf "%s\n" "$(sed -n -e "/^\s*text-color\s*:\s*[#[:alnum:]]\+;/p" "${rofi_config}")"
printf "%s\n" "$(sed -n -e "/^\s*selbg\s*:\s*[#[:alnum:]]\+;/p" "${rofi_config}")"
printf "%s\n" "$(sed -n -e "/^\s*actbg\s*:\s*[#[:alnum:]]\+;/p" "${rofi_config}")"
printf "%s\n" "$(sed -n -e "/^\s*urgbg\s*:\s*[#[:alnum:]]\+;/p" "${rofi_config}")"
printf "%s\n\n" "$(sed -n -e "/^\s*winbg\s*:\s*[#[:alnum:]]\+;/p" "${rofi_config}")"
else
echo "Colors for rofi changed"
fi
}
function change_colorscheme_bspwm() {
# sed -n -e 's/\(^.*normal_border_color\s*\)"[#[:alnum:]]\+"$/\1#282828/p' bspwmrc
sed -i -e "s/\(^.*normal_border_color\s*\)\"[#[:alnum:]]\+\"$/\1\"${background_xresources}\"/" "${bspwm_config}"
sed -i -e "s/\(^.*active_border_color\s*\)\"[#[:alnum:]]\+\"$/\1\"${background_xresources}\"/" "${bspwm_config}"
sed -i -e "s/\(^.*focused_border_color\s*\)\"[#[:alnum:]]\+\"$/\1\"${foreground_xresources}\"/" "${bspwm_config}"
if [ -n "$1" ]; then
printf "\n%s\n\n" "Colors changed for bspwm borders are: "
sed -n -e "/^.*normal_border_color\s*\"[#[:alnum:]]\+\"$/p" "${bspwm_config}"
sed -n -e "/^.*active_border_color\s*\"[#[:alnum:]]\+\"$/p" "${bspwm_config}"
sed -n -e "/^.*focused_border_color\s*\"[#[:alnum:]]\+\"$/p" "${bspwm_config}"
echo "Restarting bspwm"
else
echo "Colors for bspwm changed, restarting"
fi
bspc wm -r # reload the wm(reloads the polybar)
sleep 1 # give time to properly load wm
}
function change_colorscheme_dmenu() {
sed -i -e "s/\(^\s*\[SchemeNorm\].*{\s*\)\"[#[:alnum:]]\+\"\(.*$\)/\1\"${foreground_xresources}\"\2/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeNorm\].*{.*\)\"[#[:alnum:]]\+\"/\1\"${background_xresources}\"/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeSel\].*{\s*\)\"[#[:alnum:]]\+\"\(.*$\)/\1\"${foreground_xresources}\"\2/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeSel\].*{.*\)\"[#[:alnum:]]\+\"/\1\"${color8}\"/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeSelHighlight\].*{.*\)\"[#[:alnum:]]\+\"/\1\"${color4}\"/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeNormHighlight\].*{\s*\)\"[#[:alnum:]]\+\"\(.*$\)/\1\"${color14}\"\2/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeOut\].*{\s*\)\"[#[:alnum:]]\+\"\(.*$\)/\1\"${background_xresources}\"\2/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeOut\].*{.*\)\"[#[:alnum:]]\+\"/\1\"${color12}\"/" "${dmenu_config}"
sed -i -e "s/\(^\s*\[SchemeMid\].*{.*\)\"[#[:alnum:]]\+\"/\1\"${color2}\"/" "${dmenu_config}"
if [ -n "$1" ]; then
printf "\nColors after changing:\n\n"
printf "%s\n" "$(sed -n -e "/^\s*\[SchemeNorm\].*/p" "${dmenu_config}")"
printf "%s\n" "$(sed -n -e "/^\s*\[SchemeSel\].*/p" "${dmenu_config}")"
printf "%s\n" "$(sed -n -e "/^\s*\[SchemeSelHighlight\].*/p" "${dmenu_config}")"
printf "%s\n" "$(sed -n -e "/^\s*\[SchemeNormHighlight\].*/p" "${dmenu_config}")"
printf "%s\n" "$(sed -n -e "/^\s*\[SchemeOut\].*/p" "${dmenu_config}")"
printf "%s\n\n" "$(sed -n -e "/^\s*\[SchemeMid\].*/p" "${dmenu_config}")"
else
echo "Colors for dmenu changed, please compile it again to see effect"
fi
#cd "/home/$(logname)/Downloads/git-materials/dmenu_mybuild"
#make install
#cd -
}
function change_colorscheme_zathura() {
sed -i -e "s/\(.*default-bg\s*\)\".*\"/\1\"${background_xresources}\"/" "${zathura_config}"
sed -i -e "s/\(.*default-fg\s*\)\".*\"/\1\"${foreground_xresources}\"/" "${zathura_config}"
sed -i -e "s/\(.*statusbar-bg\s*\)\".*\"/\1\"${color8}\"/" "${zathura_config}"
sed -i -e "s/\(.*statusbar-fg\s*\)\".*\"/\1\"${color14}\"/" "${zathura_config}"
sed -i -e "s/\(.*inputbar-bg\s*\)\".*\"/\1\"${background_xresources}\"/" "${zathura_config}"
sed -i -e "s/\(.*inputbar-fg\s*\)\".*\"/\1\"${foreground_xresources}\"/" "${zathura_config}"
sed -i -e "s/\(.*notification-warning-bg\s*\)\".*\"/\1\"${color1}\"/" "${zathura_config}"
sed -i -e "s/\(.*notification-warning-bg\s*\)\".*\"/\1\"${color0}\"/" "${zathura_config}"
sed -i -e "s/\(.*highlight-color\s*\)\".*\"/\1\"${color6}\"/" "${zathura_config}"
sed -i -e "s/\(.*highlight-active-color\s*\)\".*\"/\1\"${color12}\"/" "${zathura_config}"
sed -i -e "s/\(.*completion-highlight-bg\s*\)\".*\"/\1\"${color5}\"/" "${zathura_config}"
sed -i -e "s/\(.*completion-highlight-fg\s*\)\".*\"/\1\"${color0}\"/" "${zathura_config}"
sed -i -e "s/\(.*completion-bg\s*\)\".*\"/\1\"${color8}\"/" "${zathura_config}"
sed -i -e "s/\(.*completion-fg\s*\)\".*\"/\1\"${color11}\"/" "${zathura_config}"
sed -i -e "s/\(.*notification-bg\s*\)\".*\"/\1\"${color4}\"/" "${zathura_config}"
sed -i -e "s/\(.*notification-fg\s*\)\".*\"/\1\"${color0}\"/" "${zathura_config}"
sed -i -e "s/\(.*recolor-darkcolor\s*\)\".*\"/\1\"${foreground_xresources}\"/" "${zathura_config}"
sed -i -e "s/\(.*recolor-lightcolor\s*\)\".*\"/\1\"${background_xresources}\"/" "${zathura_config}"
# [ -n "$1" ] && echo "Argument $1 recieved"
if [ -n "$1" ]; then
printf "\nColors after change:\n\n"
sed -n -e "/.*default-bg/p" "${zathura_config}"
sed -n -e "/.*default-fg/p" "${zathura_config}"
sed -n -e "/.*statusbar-bg/p" "${zathura_config}"
sed -n -e "/.*statusbar-fg/p" "${zathura_config}"
sed -n -e "/.*inputbar-bg/p" "${zathura_config}"
sed -n -e "/.*inputbar-fg/p" "${zathura_config}"
sed -n -e "/.*notification-warning-bg/p" "${zathura_config}"
sed -n -e "/.*notification-warning-bg/p" "${zathura_config}"
sed -n -e "/.*highlight-color/p" "${zathura_config}"
sed -n -e "/.*highlight-active-color/p" "${zathura_config}"
sed -n -e "/.*completion-highlight-bg/p" "${zathura_config}"
sed -n -e "/.*completion-highlight-fg/p" "${zathura_config}"
sed -n -e "/.*completion-bg/p" "${zathura_config}"
sed -n -e "/.*completion-fg/p" "${zathura_config}"
sed -n -e "/.*notification-bg/p" "${zathura_config}"
sed -n -e "/.*notification-fg/p" "${zathura_config}"
sed -n -e "/.*recolor-darkcolor/p" "${zathura_config}"
sed -n -e "/.*recolor-lightcolor/p" "${zathura_config}"
else
echo "Colors for zathura changed"
fi
}
function change_colorschemes() {
change_colorscheme_terminal
change_colorscheme_xresources
# get all the colors from Xresources, since most of the colors are used in functions few times
# so, this would reduce time
background_xresources=$(sed -n -e 's/^\s*\*.\?background\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
foreground_xresources=$(sed -n -e 's/^\s*\*.\?foreground\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color0=$(sed -n -e 's/^\s*\*.\?color0\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color1=$(sed -n -e 's/^\s*\*.\?color1\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color2=$(sed -n -e 's/^\s*\*.\?color2\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color3=$(sed -n -e 's/^\s*\*.\?color3\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color4=$(sed -n -e 's/^\s*\*.\?color4\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color5=$(sed -n -e 's/^\s*\*.\?color5\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color6=$(sed -n -e 's/^\s*\*.\?color6\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color7=$(sed -n -e 's/^\s*\*.\?color7\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color8=$(sed -n -e 's/^\s*\*.\?color8\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color9=$(sed -n -e 's/^\s*\*.\?color9\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color10=$(sed -n -e 's/^\s*\*.\?color10\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color11=$(sed -n -e 's/^\s*\*.\?color11\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color12=$(sed -n -e 's/^\s*\*.\?color12\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color13=$(sed -n -e 's/^\s*\*.\?color13\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color14=$(sed -n -e 's/^\s*\*.\?color14\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
color15=$(sed -n -e 's/^\s*\*.\?color15\s*:\s*\([#a-fA-F0-9]\+$\)/\1/p' ~/.Xresources)
change_colorscheme_bspwm "$1"
change_colorscheme_dmenu "$1"
change_colorscheme_dunst "$1"
change_colorscheme_rofi "$1"
change_colorscheme_zathura "$1"
#if [[ "${USER}" = root ]]; then
#change_colorscheme_dmenu
#fi
}
function gen_theme_file() {
. ~/.cache/temp/sh_files/vcolors.sh --gen
}
function change_vim_background() {
. ~/.cache/temp/sh_files/vcolors.sh --background $1
}
function get_help() {
cat << EOH
Usage: settheme.sh [arguments]
-h, --help shows this help
-bg, --background changes the background between light and dark for n/vim
-c, --colorscheme shows fzf menu containing installed colorschemes to Choose
colorscheme from it.
This sets colorscheme for \$TERMINAL and .Xresources as well which
in turn also changes theme for polybar and other tools too
--gen generate file with installed themes of n/vim to use with other scripts
Note: if no argument is provided then it'll be default to changing colorscheme.
Currently supported for n/vim, alacritty, termite, Xresources, polybar(with xresources), dunst and rofi
You have to compile dmenu yourself for now after runnning this script, work in progress
EOH
}
case $1 in
-h|--help) get_help ;;
-c|--colorscheme|'') change_colorschemes ;;
--gen) gen_theme_file ;;
-bg|--background) change_vim_background $2 ;;
# --check) echo "No function to check currently" ;;
--check) change_colorscheme_zathura ;;
-v|--verbose)
case $2 in
-c|--colorscheme|'') change_colorschemes "$1" ;;
*) printf "Error! Invalid argument\tTry --help" ;;
esac ;;
*) printf "Error! Invalid argument\tTry --help" ;;
esac