Files
dotfiles/xsession/bin/lupan-set-theme

66 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
THEME="$1"
if [ "$THEME" = "toggle" ]; then
if [ -e ~/.lightmode ]; then
THEME=dark
else
THEME=light
fi
fi
if [ "$THEME" = dark ]; then
GTK_THEME=Sunrise-Compact-Dark
rm -f ~/.lightmode
elif [ "$THEME" = light ]; then
GTK_THEME=Sunrise-Compact-Light
touch ~/.lightmode
else
echo "error: unknown theme: should be either dark, light or toggle" >&2
exit 1
fi
pkill -USR1 '^dwm$'
XRES=$(readlink -e ~/.Xresources)
if [ -n "$XRES" ]; then
if [ "$THEME" = dark ]; then
sed -i 's/^#undef THEME_DARK/#define THEME_DARK/' "$XRES"
elif [ "$THEME" = light ]; then
sed -i 's/^#define THEME_DARK/#undef THEME_DARK/' "$XRES"
fi
xrdb -merge "$XRES"
pkill -USR1 '^st$'
fi
# Alacritty
AYML=$(readlink -e ~/.config/alacritty/alacritty.yml)
if [ -n "$AYML" ]; then
sed -i "s/^colors: [*].*/colors: *$THEME/" "$AYML"
fi
ATOML=$(readlink -e ~/.config/alacritty/alacritty.toml)
if [ -f "$ATOML" ]; then
sed -i "s#^import =.*#import = [\"~/.config/alacritty/$THEME.toml\"]#" "$ATOML"
fi
XSET=$(readlink -e ~/.config/xsettingsd/xsettingsd.conf)
if [ "$THEME" = dark ]; then
kitten themes --reload-in=all Afterglow
elif [ "$THEME" = light ]; then
kitten themes --reload-in=all One Half Light
fi
# GTK
if [ -n "$XSET" ]; then
sed -i -E "s#(Net/ThemeName) .*#\\1 \"${GTK_THEME}\"#" "$XSET"
pkill -HUP -x xsettingsd
gsettings set org.gnome.desktop.interface gtk-theme "${GTK_THEME}"
fi
# waybar
WCSS=$(readlink -e ~/.config/waybar/style.css)
if [ -f "$WCSS" ]; then
sed -i -E "s#file:///.*/(light|dark)[.]css#file://$HOME/.config/waybar/$THEME.css#" "$WCSS"
fi