pub / theme-switchers

Switching Themes for various GNU+Linux software
git clone src.jayvii.de/pub/theme-switchers.git
Home | Log | Files | Exports | Refs | README | RSS

commit c4d97ec06afb0c3d541ede5fbd867f69df2c3629
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Sun, 12 Oct 2025 22:02:59 +0200

feat: add theme switchers for gnome and helix

Diffstat:
Aauto-themes.sh | 14++++++++++++++
Agnome-switch-theme.sh | 27+++++++++++++++++++++++++++
Ahelix-switch-theme.sh | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aswitch-themes.sh | 19+++++++++++++++++++
4 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/auto-themes.sh b/auto-themes.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# exit on error +set -e + +# change directory +cd $(dirname -- "${BASH_SOURCE[0]}") + +currenttime=$(date +%H:%M) +if [[ "$currenttime" > "17:00" || "$currenttime" < "09:00" ]]; then + ./switch-themes.sh "dark" +else + ./switch-themes.sh "light" +fi diff --git a/gnome-switch-theme.sh b/gnome-switch-theme.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# exit on error +set -eo pipefail + +# check whether input was given +if [ -z $1 ]; then + # get current GTK theme + target=$(gsettings get org.gnome.desktop.interface color-scheme) +else + target="$1" +fi + +# If we want a dark theme, but the current theme is not, switch theme to dark +if [[ "$target" == "'prefer-light'" ]] || [[ "$target" == "dark" ]]; then + gsettings set org.gnome.desktop.interface color-scheme "prefer-dark" + echo "[✓] Switched gnome to dark!" + +# If we want a light theme, but the current theme is not, switch theme to light +elif [[ "$target" == "'prefer-dark'" ]] || [[ "$target" == "light" ]]; then + gsettings set org.gnome.desktop.interface color-scheme "prefer-light" + echo "[✓] Switched gnome to light!" + +else + echo "[-] Did not switch theme: $sys_theme" + +fi diff --git a/helix-switch-theme.sh b/helix-switch-theme.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +# exit on error +set -eo pipefail + +# configuration +config_dir="$HOME/.config/helix" +config="$config_dir/config.toml" +config_theme="$config_dir/autothemes.toml" + +# gather dark and light themes from config file +if [ -f "$config_theme" ]; then + dark_theme=$( + grep -e "^\s*theme_dark" "$config_theme" | \ + sed -E -e 's/^\s*theme_dark\s*=\s*\"([^"]+)\".*$/\1/' + ) + light_theme=$( + grep -e "^\s*theme_light" "$config_theme" | \ + sed -E -e 's/^\s*theme_light\s*=\s*\"([^"]+)\".*$/\1/' + ) +else + echo " + Config file $config_theme does not exist. Please create the file, e.g.: + + theme_dark = \"adwaita-dark\" + theme_light = \"adwaita-light\" + " + exit 1 +fi + +# functions +function get_theme { + set +e + grep -c -e "^\s*theme\s*=\s*\"${1}\"" ${config} + set -e +} +function set_theme { + sed -E -e "s/^\s*(theme\s*=\s*)\"[^\"]+\"/\1\"${1}\"/" -i ${config} +} + +# check whether helix currently uses the dark theme +is_dark=$(get_theme "${dark_theme}") +is_light=$(get_theme "${light_theme}") + +# check whether input was given +if [ -z $1 ]; then + if [[ $is_dark != 0 ]]; then + target="light" + else + target="dark" + fi +else + target="$1" +fi + + +if [ "$target" == "dark" ]; then + if [[ $is_dark != 1 ]]; then + set_theme "${dark_theme}" + echo "[✓] Switched helix to dark!" + else + echo "[-] Did not switch helix theme." + fi +else + if [[ $is_light != 1 ]]; then + set_theme "${light_theme}" + echo "[✓] Switched helix to light!" + else + echo "[-] Did not switch helix theme." + fi +fi diff --git a/switch-themes.sh b/switch-themes.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# exit on error +set -e + +# change directory +cd $(dirname -- "${BASH_SOURCE[0]}") + +# call every script that is available + +## GNOME +if [ -f "./gnome-switch-theme.sh" ]; then + ./gnome-switch-theme.sh "$1" +fi + +## Helix +if [ -f "./helix-switch-theme.sh" ]; then + ./helix-switch-theme.sh "$1" +fi