This repository has been archived by the owner on Oct 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toggletheme.sh
executable file
·334 lines (271 loc) · 9.07 KB
/
toggletheme.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
#!/bin/bash
# ---------------------------------------------------------
#
# toggletheme
# - switch wallpaper, colorscheme, ... between dark / light
#
# - works best with default Breeze theme "following current color scheme"
# - window shadow color may not work with other window decorations than Breeze (breezerc)
# - script does not check if wallpaper, vs-code theme, konsole profile exist
#
# - you only need:
# - wallpaper/s for each theme
# - KDE colorschemes used here KritaDarkOrange, FlatRemixBlueDarkest
# - VS-Code themes used here: Simple Dark, Just Black
# - create Konsole profiles for your needs
#
# ---------------------------------------------------------
# #########################################################
# functions
# #########################################################
createTogglethemerc() {
echo Creating new config file $HOME/.config/togglethemerc
echo Please adjust settings and start script again!
cat << EOF > $HOME/.config/togglethemerc
# Colors used
#
# RGB colors for window border shadow
# RGB_BLACK="0,0,0" #000000
# RGB_BLUE="61,174,233" #3daee9
# RGB_BLUE_BLACK="39,119,255" #2777ff
# RGB_ORANGE="246,116,0" #ffa200
#
# HEX colors for accent
# HEX_BLUE="#3daee9"
# HEX_BLUE_BLACK="#2777ff"
# HEX_ORANGE="#ffa200"
#
#
# ::: desktoptheme - aka Plasma Style - SHOULD ALWAYS BE SET TO "default" and should be set initially for script to work!
# > plasma-apply-desktoptheme --list-themes
# default <<<--- we need this one always to follow colorscheme
# breeze-dark
# breeze-light
#
#
# ::: look-and-feel - a.k.a. Global Design
# > plasma-apply-lookandfeel -l
# org.kde.breeze.desktop
# org.kde.breezedark.desktop
# org.kde.breezetwilight.desktop <<<--- as an alternative for light
#
#
# ::: colorschemes
# > plasma-apply-colorscheme --list-schemes
#
#
# ::: cursorthemes
# > plasma-apply-cursortheme --list-themes
#
#
# ::: Wallpapers
# I recommend using links to fixed names for wallpapers instead of real filenames here
#
[General]
CurrentTheme=none
[Switch]
ColorScheme=y
DesktopTheme=y
GTKTheme=y
Icons=y
Konsole=y
LookAndFeel=y
Shadow=y
SplashScreen=n
TaskSwitcher=y
VSCode=y
Wallpaper=y
[TaskSwitcher]
Style=thumbnail_grid
[black]
ColorScheme=FlatRemixBlueDarkest
DesktopTheme=default
GTKTheme=Breeze
Icons=breeze-dark
Konsole=BlackBlue
LookAndFeel=org.kde.breezedark.desktop
Shadow=39,119,255
VSCode=Just Black
Wallpaper=/home/peter/Bilder/Wallpapers/wallpaper-black
[dark]
ColorScheme=BreezeClassicDarkInactiveDimmed
DesktopTheme=default
GTKTheme=Breeze
Icons=breeze-dark
Konsole=Breeze
LookAndFeel=org.kde.breezedark.desktop
Shadow=61,174,233
VSCode=Simple Dark
Wallpaper=/home/peter/Bilder/Wallpapers/wallpaper-dark
[darker]
ColorScheme=FlatRemixBlueDark
DesktopTheme=default
GTKTheme=Breeze
Icons=breeze-dark
Konsole=FlatRemixBlueDark
LookAndFeel=org.kde.breezedark.desktop
Shadow=39,119,255
VSCode=Atom One Dark
Wallpaper=/home/peter/Bilder/Wallpapers/wallpaper-darker
[light]
ColorScheme=BreezeClassicLight
DesktopTheme=default
GTKTheme=Breeze
Icons=breeze
Konsole=BlackOnWhite
LookAndFeel=org.kde.breeze.desktop
Shadow=0,0,0
VSCode=Default Light+
Wallpaper=/home/peter/Bilder/Wallpapers/wallpaper-light
EOF
exit 0
}
switchWallpaper() {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key Wallpaper) == "y" ]] ; then
#
# switch wallpaper
echo ::: Switch wallpaper to $1
plasma-apply-wallpaperimage $1
#
# switch lockscreen wallpaper
echo ::: Switch lockscreen background to $1
kwriteconfig5 --file kscreenlockerrc --group Greeter --group Wallpaper --group org.kde.image --group General --key Image "file://$1"
fi
}
switchDesktoptheme() {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key DesktopTheme) == "y" ]] ; then
echo ::: Switch DesktopTheme to $1
plasma-apply-desktoptheme $1
fi
}
switchLookandfeel() {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key LookAndFeel) == "y" ]] ; then
echo ::: Switch LookAndFeel to $1
plasma-apply-lookandfeel --apply $1
fi
# splashscreen none or breeze?
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key SplashScreen ) == "y" ]] ; then
# breeze is default and has an empty ksplashrc - so delete entries
echo ::: Switch SplashScreen to $1
kwriteconfig5 --file ksplashrc --group KSplash --key Engine --delete
kwriteconfig5 --file ksplashrc --group KSplash --key Theme --delete
else
echo ::: Disabling SplashScreen
kwriteconfig5 --file ksplashrc --group KSplash --key Engine None
kwriteconfig5 --file ksplashrc --group KSplash --key Theme None
fi
# use different taskswitcher?
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key TaskSwitcher) == "y" ]] ; then
TASKSWITCHER_STYLE=$(kreadconfig5 --file $CONFIG_FILE --group TaskSwitcher --key Style)
echo ::: Switch TaskSwitcher Style to $TASKSWITCHER_STYLE
kwriteconfig5 --file kwinrc --group TabBox --key LayoutName $TASKSWITCHER_STYLE
fi
}
switchGtktheme() {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key GTKTheme) == "y" ]] ; then
echo ::: Switch GTKTheme to $1
qdbus org.kde.GtkConfig /GtkConfig org.kde.GtkConfig.setGtkTheme $1
fi
}
switchColorscheme() {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key ColorScheme) == "y" ]] ; then
echo ::: Switch ColorScheme to $1
plasma-apply-colorscheme $1
fi
}
switchShadow() {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key Shadow) == "y" ]] ; then
#
# set ShadowColor (R,G,B) in $HOME/.config/breezerc
echo ::: Switch Window ShadowColor to $1
kwriteconfig5 --file breezerc --group Common --key ShadowColor $1
fi
}
switchIcons() {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key Icons) == "y" ]] ; then
echo ::: Switch Icons to $1
/usr/lib/plasma-changeicons $1
fi
}
switchKonsole () {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key Konsole) == "y" ]] ; then
#
# define Breeze.profile and BlackOnWhite.profile profiles first for konsole!
# set default profile for new instances
echo ::: Switch Konsole Profile to $1
kwriteconfig5 --file konsolerc --group "Desktop Entry" --key "DefaultProfile" $1".profile"
#
# apply to all running instances
IFS=" "
PIDS=$(pidof konsole)
for PID in $PIDS; do
qdbus org.kde.konsole-$PID /Sessions/1 org.kde.konsole.Session.setProfile $1
done
fi
}
switchVSCode () {
if [[ $(kreadconfig5 --file $CONFIG_FILE --group Switch --key VSCode) == "y" ]] ; then
#
# modify settings directly with sed in ~/.config/Code/User/settings.json
echo ::: Switch VSCode Theme to $1
sed -i -e "s/\"workbench.colorTheme\":.*$/\"workbench.colorTheme\": \"$1\",/" ~/.config/Code/User/settings.json
fi
}
# #########################################################
# main
# #########################################################
#
# check for config - create if not there or if parameter 'init' has been passed#
CONFIG_FILE=$HOME/.config/togglethemerc
if [[ ! -f $CONFIG_FILE || $1 == "init" ]] ; then
createTogglethemerc
fi
#
# get current theme for easy toggling if no parameter passed
CURRENT_THEME=$(kreadconfig5 --file $CONFIG_FILE --group General --key CurrentTheme)
if [[ $1 == "" ]] ; then
#
# no parameter - only toggle light/dark
case $CURRENT_THEME in
light)
NEW_THEME="dark"
;;
*)
NEW_THEME="light"
;;
esac
else
#
# parameter -> evaluate
case $1 in
light | dark | darker | black )
NEW_THEME=$1
;;
*)
echo Only light, dark, darker, black allowed as parameter.
exit 1
;;
esac
fi
#
# apply values from config file
switchDesktoptheme $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key DesktopTheme)
switchLookandfeel $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key LookAndFeel)
switchGtktheme $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key GTKTheme)
switchColorscheme $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key ColorScheme)
switchShadow $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key Shadow)
switchIcons $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key Icons)
switchWallpaper $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key Wallpaper)
switchKonsole $(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key Konsole)
switchVSCode "$(kreadconfig5 --file $CONFIG_FILE --group $NEW_THEME --key VSCode)"
#
# reload config to apply changes
echo ::: Reload new settings
qdbus org.kde.KWin /KWin org.kde.KWin.reconfigure
#
# write config
echo ::: Update $CONFIG_FILE settings
kwriteconfig5 --file $CONFIG_FILE --group General --key CurrentTheme $NEW_THEME
# #########################################################
# END OF SCRIPT
# #########################################################