Repository navigation
Expand file tree
/
Copy paththeme
More file actions
executable file
·140 lines (120 loc) · 2.92 KB
/
Copy paththeme
File metadata and controls
executable file
·140 lines (120 loc) · 2.92 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
#!/usr/bin/bash
set -Eeuo pipefail
source "$HOME/dotfiles/linux/variables.env"
state_file="$THEME_STATE_FILE"
current_theme() {
local theme
if [ -r "$state_file" ]; then
read -r theme < "$state_file"
else
theme=dark
fi
case "$theme" in
dark|light) printf '%s\n' "$theme" ;;
*) printf 'dark\n' ;;
esac
}
write_gtk_settings() {
local theme="$1"
local gtk_theme prefer_dark
if [ "$theme" = dark ]; then
gtk_theme=Colloid-Teal-Dark
prefer_dark=1
else
gtk_theme=Colloid-Teal-Light
prefer_dark=0
fi
for gtk_version in gtk-3.0 gtk-4.0; do
mkdir -p "$XDG_CONFIG_HOME/$gtk_version"
cat > "$XDG_CONFIG_HOME/$gtk_version/settings.ini" <<EOF
[Settings]
gtk-application-prefer-dark-theme=$prefer_dark
gtk-theme-name=$gtk_theme
gtk-icon-theme-name=Papirus-Dark
EOF
done
cat > "$HOME/.gtkrc-2.0" <<EOF
gtk-theme-name = "$gtk_theme"
gtk-icon-theme-name = "Papirus-Dark"
EOF
}
set_gsetting() {
local schema="$1"
local key="$2"
local value="$3"
if command -v gsettings > /dev/null 2>&1 && [ "$(gsettings writable "$schema" "$key" 2> /dev/null)" = true ]; then
gsettings set "$schema" "$key" "$value" || true
fi
}
apply_theme() {
local theme="$1"
local gtk_theme color_scheme kvantum_theme
if [ "$theme" = dark ]; then
gtk_theme=Colloid-Teal-Dark
color_scheme=prefer-dark
kvantum_theme=KvGnomeDark
else
gtk_theme=Colloid-Teal-Light
color_scheme=prefer-light
kvantum_theme=KvGnome
fi
write_gtk_settings "$theme"
set_gsetting org.gnome.desktop.interface color-scheme "'$color_scheme'"
set_gsetting org.gnome.desktop.interface gtk-theme "'$gtk_theme'"
set_gsetting org.gnome.desktop.interface icon-theme "'Papirus-Dark'"
if command -v kvantummanager > /dev/null 2>&1; then
kvantummanager --set "$kvantum_theme" || true
fi
}
show_notification() {
local theme="$1"
local icon summary body
if [ "$theme" = dark ]; then
icon=moon
summary="Dark mode enabled"
body="Applications will prefer dark colors."
else
icon=sun
summary="Light mode enabled"
body="Applications will prefer light colors."
fi
command -v notify-send > /dev/null 2>&1 || return 0
notify-send -a System \
-i "$LUCIDE_PATH/$icon.svg" \
-h string:wired-tag:theme \
-u low \
-t 3000 \
"$summary" "$body" || true
}
case "${1:-toggle}" in
get)
current_theme
;;
apply)
apply_theme "$(current_theme)"
;;
init)
if [ ! -r "$state_file" ]; then
mkdir -p "$(dirname "$state_file")"
printf 'dark\n' > "$state_file"
fi
apply_theme "$(current_theme)"
;;
dark|light)
mkdir -p "$(dirname "$state_file")"
printf '%s\n' "$1" > "$state_file"
apply_theme "$1"
show_notification "$1"
;;
toggle)
if [ "$(current_theme)" = dark ]; then
"$0" light
else
"$0" dark
fi
;;
*)
printf 'Usage: %s [dark|light|toggle|get|apply|init]\n' "$0" >&2
exit 2
;;
esac