81 lines
2.9 KiB
Bash
Executable file
81 lines
2.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
# "Automate" flipping applications between light and dark themes.
|
|
|
|
DOTFILES="$(cd "$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")" && pwd)"
|
|
SCHEME_FILE="${DOTFILES}/.color-scheme"
|
|
OSTYPE="$(uname -s)"
|
|
|
|
install_dark() {
|
|
ln -sf "${DOTFILES}/alacritty/colors-dark.toml" "${DOTFILES}/alacritty/colors.toml"
|
|
ln -sf "${DOTFILES}/bat/config-dark" "${DOTFILES}/bat/config"
|
|
ln -sf "${DOTFILES}/task/dark.theme" "${DOTFILES}/task/color.theme"
|
|
ln -sf "${DOTFILES}/vim/colors/jdkaplan-dark.vim" "${DOTFILES}/vim/colors/jdkaplan.vim"
|
|
ln -sf "${DOTFILES}/neovim/colors/jdkaplan-cool.lua" "${DOTFILES}/neovim/colors/jdkaplan-temp.lua"
|
|
|
|
cat "${DOTFILES}/helix/dark.toml" "${DOTFILES}/helix/main.toml" > "${DOTFILES}/helix/config.toml"
|
|
|
|
if [ "${OSTYPE}" == 'Linux' ]; then
|
|
ln -sf "${DOTFILES}/xsettingsd/xsettingsd-dark.conf" "${DOTFILES}/xsettingsd/xsettingsd.conf"
|
|
fi
|
|
|
|
if [ "${XDG_SESSION_TYPE-}" == 'wayland' ]; then
|
|
gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark'
|
|
gsettings set org.gnome.desktop.interface icon-theme 'Adwaita-dark'
|
|
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
|
|
fi
|
|
}
|
|
|
|
install_light() {
|
|
ln -sf "${DOTFILES}/alacritty/colors-light.toml" "${DOTFILES}/alacritty/colors.toml"
|
|
ln -sf "${DOTFILES}/bat/config-light" "${DOTFILES}/bat/config"
|
|
ln -sf "${DOTFILES}/task/light.theme" "${DOTFILES}/task/color.theme"
|
|
ln -sf "${DOTFILES}/vim/colors/jdkaplan-light.vim" "${DOTFILES}/vim/colors/jdkaplan.vim"
|
|
ln -sf "${DOTFILES}/neovim/colors/jdkaplan-warm.lua" "${DOTFILES}/neovim/colors/jdkaplan-temp.lua"
|
|
|
|
cat "${DOTFILES}/helix/light.toml" "${DOTFILES}/helix/main.toml" > "${DOTFILES}/helix/config.toml"
|
|
|
|
if [ "${OSTYPE}" == 'Linux' ]; then
|
|
ln -sf "${DOTFILES}/xsettingsd/xsettingsd-light.conf" "${DOTFILES}/xsettingsd/xsettingsd.conf"
|
|
fi
|
|
|
|
if [ "${XDG_SESSION_TYPE-}" == 'wayland' ]; then
|
|
gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita'
|
|
gsettings set org.gnome.desktop.interface icon-theme 'Adwaita'
|
|
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
|
|
fi
|
|
}
|
|
|
|
postinstall() {
|
|
# Alacritty doesn't automatically reload config when the symlink to
|
|
# `colors.toml` is replaced with the new target. So touch the main config
|
|
# to trigger the reload.
|
|
touch "${DOTFILES}/alacritty/alacritty.toml"
|
|
|
|
if [ "${OSTYPE}" == 'Linux' ]; then
|
|
killall --signal HUP xsettingsd
|
|
fi
|
|
}
|
|
|
|
if [ -f "${SCHEME_FILE}" ]; then
|
|
default_scheme="$(head -n 1 "${SCHEME_FILE}")"
|
|
else
|
|
default_scheme='dark'
|
|
fi
|
|
|
|
scheme="${1:-${default_scheme}}"
|
|
|
|
if [ "${scheme}" = 'dark' ]; then
|
|
install_dark
|
|
elif [ "${scheme}" = 'light' ]; then
|
|
install_light
|
|
else
|
|
echo "Unknown color scheme: ${scheme}"
|
|
exit 1
|
|
fi
|
|
|
|
postinstall
|
|
|
|
echo "$scheme" > "${SCHEME_FILE}"
|