#!/bin/sh

if [ -f "$HOME/.dark" ]
then
	sed -i -e 's/kitty_light.conf/kitty_dark.conf/' $HOME/.config/kitty/kitty.conf
	theme='Mint-Y-Dark-Pink'
	gsettings set org.cinnamon.desktop.background picture-uri "file://$HOME/wallpaper/dark.png"
	gsettings set org.cinnamon.desktop.interface cursor-theme 'DMX-White'
	gsettings set org.cinnamon.desktop.wm.preferences theme 'Mint-Y-Dark'
	gsettings set org.cinnamon.theme name "$theme"
	gsettings set org.cinnamon.desktop.interface icon-theme "$theme"
	gsettings set org.cinnamon.desktop.interface gtk-theme "$theme"
	theme=dark
else
	sed -i -e 's/kitty_dark.conf/kitty_light.conf/' $HOME/.config/kitty/kitty.conf
	theme="Mint-Y-Pink"
	gsettings set org.cinnamon.desktop.background picture-uri "file://$HOME/wallpaper/light.png"
	gsettings set org.cinnamon.desktop.interface cursor-theme 'DMX-Black'
	gsettings set org.cinnamon.desktop.wm.preferences theme 'Mint-Y'
	gsettings set org.cinnamon.theme name "$theme"
	gsettings set org.cinnamon.desktop.interface icon-theme "$theme"
	gsettings set org.cinnamon.desktop.interface gtk-theme "$theme"
	theme=light
fi

for socket in $(find /tmp/ -maxdepth 1 -name "kitty-$USER-*")
do
	if which kitty > /dev/null; then
		cat $HOME/darkrc/kitty_$theme.conf |\
			grep '^[[:alpha:]]' |\
			sed -s 's/ \+/=/' |\
			sed -s 's/^.*$/set-colors --all \0/' |\
			sort |\
			kitty @ --to unix:$socket >/dev/null
	fi
done

pkill -SIGUSR1 conky