2023-10-28 12:49:49 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Toggle light- or dark-mode for your applications
|
|
|
|
# Usage: toggle [-m light|dark]
|
|
|
|
|
|
|
|
#################
|
|
|
|
### Variables ###
|
|
|
|
#################
|
|
|
|
|
|
|
|
THEME_LIGHT='tdpeuter-light'
|
|
|
|
THEME_DARK='tdpeuter-dark'
|
|
|
|
THEME_DEFAULT="${THEME_LIGHT}"
|
|
|
|
|
|
|
|
STATE_FILE="${HOME}/.local/state/sisyphus/theme"
|
|
|
|
|
|
|
|
declare -A theme_next
|
|
|
|
theme_next[${THEME_LIGHT}]="${THEME_DARK}"
|
|
|
|
theme_next[${THEME_DARK}]="${THEME_LIGHT}"
|
|
|
|
|
|
|
|
declare -A gsettings_alt
|
|
|
|
gsettings_alt[${THEME_LIGHT}]='default'
|
|
|
|
gsettings_alt[${THEME_DARK}]='prefer-dark'
|
|
|
|
|
2023-11-06 10:45:26 +01:00
|
|
|
declare -A wallpaper
|
|
|
|
wallpaper[${THEME_LIGHT}]="bg"
|
|
|
|
wallpaper[${THEME_DARK}]="bg-dark"
|
|
|
|
|
2023-10-28 12:49:49 +02:00
|
|
|
#############
|
|
|
|
### Logic ###
|
|
|
|
#############
|
|
|
|
|
|
|
|
# Parse options
|
|
|
|
while getopts ":m:" option; do
|
|
|
|
case "${option}" in
|
|
|
|
m)
|
|
|
|
if [ "${OPTARG}" == 'light' ]; then
|
|
|
|
theme="${THEME_LIGHT}"
|
|
|
|
elif [ "${OPTARG}" == 'dark' ]; then
|
|
|
|
theme="${THEME_DARK}"
|
|
|
|
else
|
|
|
|
>&2 printf "Error: Invalid mode: '%s'.\nShould be either 'light' or 'dark'\n" "${option}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
>&2 printf "Error: Invalid option: '%s'.\n" "${option}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
|
|
|
# Check if the state file exists
|
|
|
|
if ! [ -d "$(dirname ${STATE_FILE})" ]; then
|
|
|
|
mkdir -p "$(dirname ${STATE_FILE})"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Choose next theme
|
|
|
|
previous_theme="$(cat ${STATE_FILE})"
|
|
|
|
if ! [[ -z "${previous_theme}" || "${theme}" ]]; then
|
|
|
|
theme="${theme_next[${previous_theme}]}"
|
|
|
|
fi
|
|
|
|
echo "${theme:=${THEME_DEFAULT}}" > "${STATE_FILE}"
|
|
|
|
|
|
|
|
######################
|
|
|
|
### Set all themes ###
|
|
|
|
######################
|
|
|
|
|
|
|
|
# GNOME
|
|
|
|
if [ "$(command -v gsettings)" ]; then
|
2023-11-06 10:45:26 +01:00
|
|
|
gsettings set org.gnome.desktop.interface color-scheme "${gsettings_alt[${theme}]}" &
|
2023-10-28 12:49:49 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Kitty
|
|
|
|
if [ "$(command -v kitty)" ]; then
|
2023-11-06 10:45:26 +01:00
|
|
|
kitten themes --reload-in all --config-file-name theme.conf "${theme}" &
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Sway
|
|
|
|
if [ "$(command -v swaybg)" ]; then
|
|
|
|
pkill swaybg && swaybg -i ~/Nextcloud/Afbeeldingen/wallpapers/${wallpaper[${theme}]} && swaymsg reload &
|
2023-10-28 12:49:49 +02:00
|
|
|
fi
|
|
|
|
|
2023-11-02 17:05:09 +01:00
|
|
|
# Vifm
|
|
|
|
if [ "$(command -v vifm)" ]; then
|
|
|
|
echo "colorscheme ${theme} Default-256 Default" > ~/.config/vifm/theme.conf
|
|
|
|
# Update all running instances
|
2023-11-06 10:45:26 +01:00
|
|
|
vifm --remote -c "colorscheme ${theme}" &
|
2023-11-02 17:05:09 +01:00
|
|
|
fi
|
|
|
|
|
2023-10-28 12:49:49 +02:00
|
|
|
# Vim
|
|
|
|
if [ "$(command -v vim)" ]; then
|
|
|
|
echo "colorscheme ${theme}" > ~/.vim/theme.conf
|
2023-11-06 10:45:26 +01:00
|
|
|
# Update all running instances
|
|
|
|
for server in $(vim --serverlist); do
|
|
|
|
vim --servername "${server}" --remote-send "<C-\><C-N>:colorscheme ${theme}<CR>"
|
|
|
|
done
|
2023-10-28 12:49:49 +02:00
|
|
|
fi
|
|
|
|
|