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 3df01707baa50430ee679d049fc3c20323f8f286
parent 2e2c0b32e0dac467ad55b797c40057ced381891c
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Thu, 16 Apr 2026 18:52:48 +0200

feat: add term theme switch

Diffstat:
Mswitch-themes.sh | 6++++++
Aterm-switch-theme.sh | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/switch-themes.sh b/switch-themes.sh @@ -17,3 +17,9 @@ fi if [ -f "./helix-switch-theme.sh" ]; then ./helix-switch-theme.sh "$1" fi + +## Bash +if [ -f "./term-switch-theme.sh" ]; then + ./term-switch-theme.sh "$1" +fi + diff --git a/term-switch-theme.sh b/term-switch-theme.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# exit on error +set -eo pipefail + +# figure out which shell we are running +shell=$(echo $SHELL | sed -E -e 's/^.*\///') + +if [[ ! -f /tmp/theme-switch-term-status ]]; then + touch /tmp/theme-switch-term-status +fi + +if [[ $(cat /tmp/theme-switch-term-status) == "$1" ]]; then + echo "[-] Did not switch theme: $1" + exit 1 +fi + +# define theme color based on given input +if [[ $1 == "dark" ]]; then + fg="#ffffff" + bg="#111111" + col0="#073642" # black + col1="#dc322f" # red + col2="#859900" # green + col3="#b58900" # yellow + col4="#268bd2" # blue + col5="#d33682" # magenta + col6="#2aa198" # cyan + col7="#eee8d5" # white +elif [[ $1 == "light" ]]; then + fg="#000000" + bg="#f7f7f7" + col0="#08404f" # bright black + col1="#e35f5c" # bright red + col2="#9fb700" # bright green + col3="#d9a400" # bright yellow + col4="#4ba1de" # bright blue + col5="#dc619d" # bright magenta + col6="#32c1b6" # bright cyan + col7="#ffffff" # bright white +else + exit 1; +fi + +# apply theme to all running shell sessions +for i in $(pgrep $shell); do + # foreground + printf "\e]10;${fg}\007" >> /proc/$i/fd/0 + # background + printf "\e]11;${bg}\007" >> /proc/$i/fd/0 + # black + printf "\e]0;${col0}\007" >> /proc/$i/fd/0 + # red + printf "\e]1;${col1}\007" >> /proc/$i/fd/0 + # green + printf "\e]2;${col2}\007" >> /proc/$i/fd/0 + # yellow + printf "\e]3;${col3}\007" >> /proc/$i/fd/0 + # blue + printf "\e]4;${col4}\007" >> /proc/$i/fd/0 + # magenta + printf "\e]5;${col5}\007" >> /proc/$i/fd/0 + # cyan + printf "\e]6;${col6}\007" >> /proc/$i/fd/0 + # white + printf "\e]7;${col7}\007" >> /proc/$i/fd/0 +done + +# user output +if [[ $(cat /tmp/theme-switch-term-status) != "$1" ]]; then + echo "$1" | tee /tmp/theme-switch-term-status > /dev/null + echo "[✓] Switched $shell to $1!" +fi