-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_theme
executable file
·182 lines (128 loc) · 3.5 KB
/
change_theme
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
#!/usr/bin/env bash
# Change the following themes:
# dunst
# kitty
# nvim
# tmux
# wallpaper
# XMonad
# Xmobar
# X resources
# zathura
#
# The following supports hot reload:
# kitty
# tmux
# wallpaper
# XMonad
# Xmobar
#
# $1 - theme
#
# Supported themes are
# latte (https://github.com/catppuccin/catppuccin)
# macchiato (https://github.com/catppuccin/catppuccin)
# nord (https://www.nordtheme.com)
# onedark
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Source helper script.
source "$DIR/lib/helper.sh"
if [ -z "$1" ]; then
echoerr "Missing argument"
exit 1
fi
catpuccins=("latte" "frappe" "macchiato" "mocha")
config_dir="$HOME/.config"
theme="$1"
change_line() {
grep -q "$2" "$3" && return
sed -i "s|$1|$2|g" "$3" || echo "Cannot modify $3"
}
change_theme_dunst() {
if ! is_linux; then
return 1
fi
rc="$config_dir/dunst/dunstrc"
# Check whether chosen theme is already in use
grep -q "^# Theme $theme" "$rc" && return
# Comment current theme block
# Starts with e.g., "# Theme macchiato {{{"
# Ends with "# }}}"
sed -i '/^# Theme .*/,/^# }}}/ s/^/#/' "$rc"
# Uncomment the chosen theme
# Starts with e.g., "## Theme nord {{{"
# Ends with "## }}}"
sed -i "/## Theme $theme .*/,/## }}}/ s/^#//g" "$rc"
killall dunst
}
change_theme_fzf() {
change_line "my_export MYTHEME \".*" "my_export MYTHEME \"$theme\"" "$config_dir"/my-shell/export.sh
}
change_theme_kitty() {
change_line "include ./themes/.*" "include ./themes/$theme.conf" "$config_dir"/kitty/kitty-all.conf
# Send kitty the SIGUSR1 to reload the config file
# https://sw.kovidgoyal.net/kitty/conf/
kill -SIGUSR1 $(pgrep kitty)
}
change_theme_nvim() {
nvim_theme="$theme"
# e.g., latte -> catpuccin-latte
[[ " ${catpuccins[@]} " =~ " ${theme} " ]] && nvim_theme="catppuccin-$theme"
change_line "local colorscheme = .*" "local colorscheme = \"$nvim_theme\"" "$config_dir"/nvim/lua/user/colorscheme.lua
}
change_theme_wallpaper() {
if ! is_linux; then
return 1
fi
# Check whether chosen theme is already in use
grep -q "$theme" "$HOME/.fehbg" && return
wallpaper="$config_dir/my-wallpaper/$theme.png"
[ ! -e "$wallpaper" ] && return 1
feh --bg-scale "$wallpaper"
betterlockscreen -u "$wallpaper"
}
change_theme_xmobar() {
if ! is_linux; then
return 1
fi
xmobardir="$config_dir/xmobar"
xmobarhs="$xmobardir/xmobar.hs"
change_line "myTheme = .*Theme" "myTheme = ${theme}Theme" "$xmobarhs"
# recompile Xmobar
pushd "$xmobardir" || return 1
stack ghc -- --make -o "$HOME/.local/bin/xmobar" "$xmobarhs"
popd || return 1
}
change_theme_xmonad() {
if ! is_linux; then
return 1
fi
change_line "myTheme = .*Theme" "myTheme = ${theme}Theme" "$config_dir/xmonad/xmonad.hs"
xmonad --restart
}
change_theme_xresources() {
if ! is_linux; then
return 1
fi
file="$HOME/.Xresources"
change_line "#include \".Xresources.d/theme-.*" "#include \".Xresources.d/theme-$theme\"" "$file"
xrdb "$file"
}
change_theme_zathura() {
if ! is_linux; then
return 1
fi
file="$config_dir/zathura/zathurarc"
change_line "include theme-.*" "include theme-$theme" "$file"
}
# Xmobar must be changed before XMonad
change_theme_xmobar
change_theme_xmonad
change_theme_dunst
change_theme_fzf
change_theme_kitty
change_theme_nvim
change_theme_tmux "$theme"
change_theme_wallpaper
change_theme_xresources
change_theme_zathura