diff options
author | mynacol | 2021-02-05 21:15:22 +0100 |
---|---|---|
committer | mynacol | 2021-02-05 21:42:28 +0100 |
commit | ccde96687b6c833fa45931812fdb8040c6737bf2 (patch) | |
tree | d01e304e6efc08fd2ca8b3ffecccb49d44fa122c /dark-theme.sh | |
download | aur-ccde96687b6c833fa45931812fdb8040c6737bf2.tar.gz |
First commit
Diffstat (limited to 'dark-theme.sh')
-rwxr-xr-x | dark-theme.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/dark-theme.sh b/dark-theme.sh new file mode 100755 index 000000000000..8a4486cc5799 --- /dev/null +++ b/dark-theme.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +# Inspiration: https://www.reddit.com/r/unixporn/comments/f1oied/awesome_global_nightday_switch_for_gtk_vim/ + +# Requirements: +# glib2: for gsettings for GTK switching under Wayland +# xfce4-settings: for xfsettings for GTK switching under Xorg +# qt5ct: for Qt5 switching +# adwaita-qt: as Qt5 theme +# sed: for switching multiple things by editing config files +# jq: for switching code by editing JSON +# moreutils: providing sponge for in-place editing code config file +# feh: for setting wallpaper under Xorg +# sway: for setting wallpaper in sway + +# enable "strict mode" +set -euo pipefail +IFS=$'\n\t' + +CURRENT=$(gsettings get org.gnome.desktop.interface gtk-theme) + +if [[ $1 == "dark" ]]; then + UI_THEME_GTK="Adwaita-dark" + UI_THEME_QT="Adwaita-Dark" + UI_VSCODE="Default Dark+" + UI_ALACRITTY="dark" + BG_X11="-B black ${HOME}/.wallpaper/light.png" + BG_SWAY="--color #000000 --image ${HOME}/.wallpaper/light.png" +elif [[ $1 == "light" ]]; then + UI_THEME_GTK="Adwaita" + UI_THEME_QT="Adwaita" + UI_VSCODE="Default Light+" + UI_ALACRITTY="light" + BG_X11="-B white ${HOME}/.wallpaper/dark.png" + BG_SWAY="--color #ffffff --image ${HOME}/.wallpaper/dark.png" +elif [[ $1 == "toggle" ]]; then + [[ "$CURRENT" == *"dark"* ]] && exec $0 light || exec $0 dark +elif [[ $1 == "reapply" ]]; then + [[ "$CURRENT" == *"dark"* ]] && exec $0 dark || exec $0 light +else + exit 1 +fi + + +# set GTK theme +if [[ "$XDG_SESSION_TYPE" == "x11" ]]; then + # Start xfsettingsd - alreday running xfsettingd ignores this + xfsettingsd --daemon + # set GTK theme xia xsettings + xfconf-query -c xsettings -p /Net/ThemeName -s "$UI_THEME_GTK" + #xfconf-query -c xsettings -p /Net/IconThemeName -s "$UI_ICONS" +else + # set GTK theme via gsettings + gsettings set org.gnome.desktop.interface gtk-theme "$UI_THEME_GTK" +fi + +# set Qt theme +sed -i -E "s@^style=.*@style=${UI_THEME_QT}@" ~/.config/qt5ct/qt5ct.conf + +# set alacritty theme +sed -i -E "s/^colors: \*.*$/colors: *$UI_ALACRITTY/" ~/.config/alacritty/alacritty.yml + +# set vscode theme +f="$HOME/.config/Code - OSS/User/settings.json" +jq ".[\"workbench.colorTheme\"]=\"${UI_VSCODE}\"" "$f" | sponge "$f" + +# set background +if [[ "$XDG_SESSION_TYPE" == "x11" ]]; then + feh --no-fehbg --bg-center ${BG_X11} +elif [[ -n "$SWAYSOCK" ]]; then + killall -q swaybg + swaybg --mode center "$BG_SWAY" & +else + echo "No supported window manager." + echo "Not setting background" +fi |