-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathswitch-theme
More file actions
executable file
·464 lines (434 loc) · 16.3 KB
/
switch-theme
File metadata and controls
executable file
·464 lines (434 loc) · 16.3 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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
#!/bin/bash
# SPDX-FileCopyrightText: 2017 - 2024 sudorook <daemon@nullcodon.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
set -euo pipefail
ROOT="$(dirname "${0}")"
source "${ROOT}"/globals
! check_command sed && exit 3
switch_dconf_cinnamon_theme() {
! check_command dconf && return
dconf write /org/cinnamon/desktop/interface/gtk-theme "'${1}'"
dconf write /org/cinnamon/desktop/wm/preferences/theme "'${1}'"
if [[ "${1}" =~ "-Eta" ]]; then
dconf write /org/cinnamon/theme/name "'${1%-*}'"
elif [[ "${1}" =~ "-Compact" ]]; then
dconf write /org/cinnamon/theme/name "'${1%-*}'"
elif [[ "${1}" =~ "-Darker" ]]; then
dconf write /org/cinnamon/theme/name "'${1%er}'"
elif [[ "${1}" =~ "-Lighter" ]]; then
dconf write /org/cinnamon/theme/name "'${1%-*}'"
else
dconf write /org/cinnamon/theme/name "'${1}'"
fi
}
switch_dconf_gnome_theme() {
! check_command dconf && return
dconf write /org/gnome/desktop/wm/preferences/theme "'${1}'"
dconf write /org/gnome/desktop/interface/gtk-theme "'${1}'"
gnome-extensions enable "user-theme@gnome-shell-extensions.gcampax.github.com" || true > /dev/null
if [[ "${1}" =~ "-Lighter" ]]; then
dconf write /org/gnome/shell/extensions/user-theme/name "'${1%-*}'"
else
dconf write /org/gnome/shell/extensions/user-theme/name "'${1}'"
fi
}
switch_plasma_theme() {
! check_command qdbus plasma-apply-lookandfeel && return
case "${1,,}" in
arc)
! check_command kvantummanager && return
plasma-apply-lookandfeel -a com.github.sudorook.arc
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Arc"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "kvantum"
kvantummanager --set Arc
;;
arcdark | arc-dark)
! check_command kvantummanager && return
plasma-apply-lookandfeel -a com.github.sudorook.arc-dark
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Arc-Dark"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "kvantum"
kvantummanager --set ArcDark
;;
arc-darker | arcdarker)
! check_command kvantummanager && return
plasma-apply-lookandfeel -a com.github.sudorook.arc-darker
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Arc-Darker"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "kvantum"
kvantummanager --set ArcDarker
;;
breeze)
plasma-apply-lookandfeel -a org.kde.breeze.desktop
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Breeze"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "Breeze"
sudo kwriteconfig5 --file "/etc/sddm.conf.d/kde_settings.conf" --group Theme --key Current "breeze"
sudo kwriteconfig5 --file "/etc/sddm.conf.d/kde_settings.conf" --group Theme --key CursorTheme "breeze_cursors"
;;
breeze-dark | breezedark)
plasma-apply-lookandfeel -a org.kde.breezedark.desktop
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Breeze"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "Breeze"
sudo kwriteconfig5 --file "/etc/sddm.conf.d/kde_settings.conf" --group Theme --key Current "breeze"
sudo kwriteconfig5 --file "/etc/sddm.conf.d/kde_settings.conf" --group Theme --key CursorTheme "breeze_cursors"
;;
breeze-twilight | breezetwilight)
plasma-apply-lookandfeel -a org.kde.breezetwilight.desktop
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Breeze"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "Breeze"
sudo kwriteconfig5 --file "/etc/sddm.conf.d/kde_settings.conf" --group Theme --key Current "breeze"
sudo kwriteconfig5 --file "/etc/sddm.conf.d/kde_settings.conf" --group Theme --key CursorTheme "breeze_cursors"
;;
materia)
! check_command kvantummanager && return
plasma-apply-lookandfeel -a com.github.sudorook.materia
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Materia"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "kvantum"
kvantummanager --set Materia
;;
materiadark | materia-dark)
! check_command kvantummanager && return
plasma-apply-lookandfeel -a com.github.sudorook.materia-dark
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Materia-dark"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "kvantum"
kvantummanager --set MateriaDark
;;
materialight | materia-light)
! check_command kvantummanager && return
plasma-apply-lookandfeel -a com.github.sudorook.materia-light
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme "Materia-light"
kwriteconfig5 --file kdeglobals --group "KDE" --key "widgetStyle" "kvantum"
kvantummanager --set MateriaLight
;;
*)
show_error "ERROR: ${1@Q} not supported. Exiting."
;;
esac
dbus-send --session --type=signal /KGlobalSettings \
org.kde.KGlobalSettings.notifyChange int32:2 int32:0
}
switch_environment_d_gtk_theme() {
local envvarconf="${HOME}/environment.d/envvars.conf"
if [ -f "${envvarconf}" ]; then
sed -i "s/^GTK_THEME=.*$/GTK_THEME=${1}/g" "${envvarconf}"
fi
}
switch_xprofile_gtk_theme() {
local xprofile="${HOME}/.xprofile"
if [ -f "${xprofile}" ]; then
sed -i "s/^export GTK_THEME=.*$/export GTK_THEME=\"${1}\"/g" "${xprofile}"
fi
}
get_gnome_terminal_profiles() {
! check_command dconf && return
IFS=' ' read -r -a ids <<< \
"$(dconf read /org/gnome/terminal/legacy/profiles:/list | tr -d "[]',")"
NAMES=()
for id in "${ids[@]}"; do
NAMES+=("$(dconf read "/org/gnome/terminal/legacy/profiles:/:${id}/visible-name")")
done
}
switch_gnome_terminal_profile() {
! check_command dconf && return
local idx=0
local name
for name in "${NAMES[@]}"; do
if [ "${name}" = "'${1}'" ]; then
dconf write /org/gnome/terminal/legacy/profiles:/default "'${ids[${idx}]}'"
fi
idx=$((idx + 1))
done
}
switch_vim_theme() {
if [ -f "${HOME}/.vimrc" ]; then
sed -i "s/^set background=.*$/set background=${1//[0-9]/}/g" "${HOME}/.vimrc"
sed -i "s/^ let g:colorific_style='.*'$/ let g:colorific_style='${1}'/g" "${HOME}/.vimrc"
sed -i "s/^set bg=.*$/set bg=${1}/g" "${HOME}/.vimrc"
fi
}
switch_neovim_theme() {
if [ -f "${HOME}/.config/nvim/init.vim" ]; then
sed -i "s/^set background=.*$/set background=${1//[0-9]/}/g" "${HOME}/.config/nvim/init.vim"
sed -i "s/^ let g:colorific_style='.*'$/ let g:colorific_style='${1}'/g" "${HOME}/.config/nvim/init.vim"
sed -i "s/^set bg=.*$/set bg=${1}/g" "${HOME}/.config/nvim/init.vim"
fi
}
switch_alacritty_theme() {
if [ -f "${HOME}/.config/alacritty/colorific.yml" ]; then
sed -i "s/^\(colors: \*\).*/\1${1}/g" "${HOME}/.config/alacritty/colorific.yml"
elif [ -f "${HOME}/.config/alacritty/themes.yml" ]; then
sed -i "s/^\(colors: \*\).*/\1${1}/g" "${HOME}/.config/alacritty/themes.yml"
elif [ -f "${HOME}/.config/alacritty/alacritty.yml" ]; then
sed -i "s/^\(colors: \*\).*/\1${1}/g" "${HOME}/.config/alacritty/alacritty.yml"
fi
}
switch_kitty_theme() {
if [ -f "${HOME}/.config/kitty/kitty.conf" ]; then
sed -i "s/^\(include .*\)\/\(\S\+.conf\)$/\1\/${1}.conf/g" "${HOME}/.config/kitty/kitty.conf"
fi
}
switch_tmux_theme() {
if [ -f "${HOME}/.tmux.conf" ]; then
local themestring
themestring=$(sed -n "s/^\ *\"source-file\ \(.*\)\"$/\1/p" "${HOME}/.tmux.conf")
if [[ "$(basename "${themestring}")" = "colorific.tmuxtheme" ]]; then
local themefile
eval themefile="${themestring}"
sed -i "s,^theme=\"[a-z0-9]\+\",theme=\"${1}\",g" "${themefile}"
else
local themedir
themedir="$(dirname "${themestring}")"
sed -i "s,${themestring},${themedir}/${1}.tmuxtheme,g" "${HOME}/.tmux.conf"
fi
fi
}
switch_thunderbird_theme() {
if [[ -v thunderbirddir ]] && [ -d "${thunderbirddir}/chrome" ]; then
local userchrome="${thunderbirddir}/chrome/userChrome.css"
if [ "${1}" = "Dark" ]; then
sed -i "s,^\(@import \"icons/darkIcons.css\"; /\*For light Folder Tree and Message List\*/\),/\* \1,g" "${userchrome}"
sed -i "s,^/\* \(@import \"icons/lightIcons.css\"; /\*For dark Folder Tree and Message List\*/\),\1,g" "${userchrome}"
sed -i "s,^/\* \(@import \"tweaks/dark-folder-pane.css\";\),\1,g" "${userchrome}"
elif [ "${1}" = "Light" ]; then
sed -i "s,^/\* \(@import \"icons/darkIcons.css\"; /\*For light Folder Tree and Message List\*/\),\1,g" "${userchrome}"
sed -i "s,^/\* \(@import \"icons/lightIcons.css\"; /\*For dark Folder Tree and Message List\*/\),\1,g" "${userchrome}"
sed -i "s,^\(@import \"tweaks/dark-folder-pane.css\";\),/\* \1,g" "${userchrome}"
sed -i "s/^set background=.*$/set background=light/g" "${userchrome}"
fi
fi
}
switch_gtk_settings() {
local gtksettings="${HOME}/.config/gtk-3.0/settings.ini"
if [[ -f ${gtksettings} ]]; then
if [ "${1}" = "Dark" ]; then
sed -i "s/^gtk-application-prefer-dark-theme=false$/gtk-application-prefer-dark-theme=true/g" "${gtksettings}"
sed -i "s/^gtk-application-prefer-dark-theme=0$/gtk-application-prefer-dark-theme=1/g" "${gtksettings}"
elif [ "${1}" = "Light" ]; then
sed -i "s/^gtk-application-prefer-dark-theme=true$/gtk-application-prefer-dark-theme=false/g" "${gtksettings}"
sed -i "s/^gtk-application-prefer-dark-theme=1$/gtk-application-prefer-dark-theme=0/g" "${gtksettings}"
fi
fi
}
switch_gitk_theme() {
local gitkdir="${HOME}/.config/git"
[[ -f "${gitkdir}/gitk-${1}" ]] && cp "${gitkdir}/gitk-${1}" "${gitkdir}/gitk"
}
switch_ebook_viewer_theme() {
local calibresettings="${HOME}/.config/calibre/viewer-webengine.json"
if [[ -f ${calibresettings} ]]; then
if [ "${1}" = "Dark" ]; then
sed -i 's/\("current_color_scheme"\): "sepia-light"/\1: "sepia-dark"/g' \
"${calibresettings}"
sed -i 's/\("current_color_scheme"\): "white"/\1: "black"/g' \
"${calibresettings}"
elif [ "${1}" = "Light" ]; then
sed -i 's/\("current_color_scheme"\): "sepia-dark"/\1: "sepia-light"/g' \
"${calibresettings}"
sed -i 's/\("current_color_scheme"\): "black"/\1: "white"/g' \
"${calibresettings}"
fi
fi
}
set_theme() {
if ! [[ -v XDG_CURRENT_DESKTOP ]]; then
return
fi
case ${XDG_CURRENT_DESKTOP} in
X-Cinnamon)
switch_dconf_cinnamon_theme "${1}"
;;
ubuntu:GNOME | GNOME)
switch_dconf_gnome_theme "${1}"
;;
KDE)
switch_plasma_theme "${1}"
;;
*)
show_error "${XDG_CURRENT_DESKTOP} environment not supported."
exit 3
;;
esac
switch_environment_d_gtk_theme "${1}"
switch_xprofile_gtk_theme "${1}"
case "${1,,}" in
adapta-nokto | adapta-nokto-eta | adaptanokto | adaptanoktoeta)
switch_gtk_settings "Dark"
switch_gnome_terminal_profile "Dark"
switch_alacritty_theme "dark"
switch_kitty_theme "dark"
switch_vim_theme "dark"
switch_neovim_theme "dark"
switch_tmux_theme "dark"
switch_thunderbird_theme "Dark"
switch_gitk_theme "dark"
switch_ebook_viewer_theme "Dark"
;;
arc-dark | arcdark)
switch_gtk_settings "Dark"
switch_gnome_terminal_profile "Dark"
switch_alacritty_theme "dark3"
switch_kitty_theme "dark3"
switch_vim_theme "dark3"
switch_neovim_theme "dark3"
switch_tmux_theme "dark3"
switch_thunderbird_theme "Dark"
switch_gitk_theme "dark3"
switch_ebook_viewer_theme "Dark"
;;
plata-noir | platanoir | plata-noir-compact | platanoircompact | materia | materia-dark | materiadark | breeze-dark | breezedark)
switch_gtk_settings "Dark"
switch_gnome_terminal_profile "Dark"
switch_alacritty_theme "dark2"
switch_kitty_theme "dark2"
switch_vim_theme "dark2"
switch_neovim_theme "dark2"
switch_tmux_theme "dark2"
switch_thunderbird_theme "Dark"
switch_gitk_theme "dark2"
switch_ebook_viewer_theme "Dark"
;;
adapta | adapta-eta | adaptaeta)
switch_gtk_settings "Light"
switch_gnome_terminal_profile "Light"
switch_alacritty_theme "light"
switch_kitty_theme "light"
switch_vim_theme "light"
switch_neovim_theme "light"
switch_tmux_theme "light"
switch_thunderbird_theme "Light"
switch_gitk_theme "light"
switch_ebook_viewer_theme "Light"
;;
arc | arc-lighter | arclighter | arc-darker | arcdarker | arc-solid | arcsolid | arc-lighter-solid | arclightersolid | arc-dark-solid | arcdarksolid)
switch_gtk_settings "Light"
switch_gnome_terminal_profile "Light"
switch_alacritty_theme "light3"
switch_kitty_theme "light3"
switch_vim_theme "light3"
switch_neovim_theme "light3"
switch_tmux_theme "light3"
switch_thunderbird_theme "Light"
switch_gitk_theme "light3"
switch_ebook_viewer_theme "Light"
;;
materia-light | materialight | breeze | breeze-twilight | breezetwilight)
switch_gtk_settings "Light"
switch_gnome_terminal_profile "Light"
switch_alacritty_theme "light2"
switch_kitty_theme "light2"
switch_vim_theme "light2"
switch_neovim_theme "light2"
switch_tmux_theme "light2"
switch_thunderbird_theme "Light"
switch_gitk_theme "light2"
switch_ebook_viewer_theme "Light"
;;
*)
show_error "ERROR: theme ${1@Q} not understood. Exiting."
exit 3
;;
esac
}
set_icon_theme() {
! [[ -v XDG_CURRENT_DESKTOP ]] && return
case ${XDG_CURRENT_DESKTOP} in
X-Cinnamon)
dconf write /org/cinnamon/desktop/interface/icon-theme "'${1}'"
;;
ubuntu:GNOME | GNOME)
dconf write /org/gnome/desktop/interface/icon-theme "'${1}'"
;;
KDE)
local exec_changeicons
if [ -e "/usr/lib/plasma-changeicons" ]; then
exec_changeicons="/usr/lib/plasma-changeicons"
elif [ -e "/usr/lib/x86_64-linux-gnu/plasma-changeicons" ]; then
exec_changeicons="/usr/lib/x86_64-linux-gnu/plasma-changeicons"
else
show_warning "WARNING: 'plasma-changeicons' not found. Skipping."
return
fi
case "${1,,}" in
breeze)
"${exec_changeicons}" "breeze"
;;
breeze-dark | breezedark)
"${exec_changeicons}" "breeze-dark"
;;
epapirus)
"${exec_changeicons}" "ePapirus"
;;
epapirus-dark | epapirusdark)
"${exec_changeicons}" "ePapirus-Dark"
;;
papirus)
"${exec_changeicons}" "Papirus"
;;
papirus-dark | papirusdark)
"${exec_changeicons}" "Papirus-Dark"
;;
papirus-light | papiruslight)
"${exec_changeicons}" "Papirus-Light"
;;
*)
"${exec_changeicons}" "${1}"
;;
esac
;;
*)
show_error "${XDG_CURRENT_DESKTOP} environment not supported."
exit 3
;;
esac
local qt5ctconf=${HOME}/.config/qt5ct/qt5ct.conf
if [ -f "${qt5ctconf}" ]; then
sed -i "s/^icon_theme=.*$/icon_theme=${1}/g" "${qt5ctconf}"
fi
}
print_usage() {
show_header "Usage: switch-theme"
show_listitem " -t|--theme <theme name>"
show_listitem " -i|--icon <icon theme name>"
show_listitem " -h|--help print (this) help message"
}
OPTIONS=t:hi:
LONGOPTIONS=theme:,help,icon:
PARSED=$(getopt -o "${OPTIONS}" --long "${LONGOPTIONS}" -n "${0}" -- "${@}")
eval set -- "${PARSED}"
get_gnome_terminal_profiles
while [ ${#} -ge 1 ]; do
case "${1}" in
-t | --theme)
set_theme "${2}"
shift 2
;;
-h | --help)
print_usage
exit
;;
-i | --icon)
set_icon_theme "${2}"
shift 2
;;
--)
shift
break
;;
*)
show_error "Error"
exit 3
;;
esac
done