add change-theme script
authorAmin Bandali <bandali@gnu.org>
Tue, 19 Oct 2021 04:36:37 +0000 (00:36 -0400)
committerAmin Bandali <bandali@gnu.org>
Tue, 19 Oct 2021 04:36:37 +0000 (00:36 -0400)
allows changing themes for future application instances as well as
currently-running ones on the fly.  xterm and emacs have been tested
and are known to work so far.

.bashrc
.config/i3/config
.local/bin/change-theme [new file with mode: 0755]

diff --git a/.bashrc b/.bashrc
index 321c1de..471b1a4 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -60,7 +60,7 @@ HISTFILESIZE=
 # history.
 HISTCONTROL=ignoreboth
 # ignore a few very common commands and don't add them to history
-HISTIGNORE='ls:l:s:g:[bf]g:history'
+HISTIGNORE='ls:l:ll:s:g:[bf]g:history:da:li'
 HISTTIMEFORMAT='%F %T '
 stty stop ""
 
@@ -84,6 +84,9 @@ alias e="$EDITOR"
 alias se="SUDO_EDITOR=\"emacsclient\" sudo -e"
 alias s="startx"
 
+alias da='change-theme dark'
+alias li='change-theme light'
+
 alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
 complete -F _quilt_completion -o filenames dquilt
 
index 05bc178..c796761 100644 (file)
@@ -167,6 +167,17 @@ mode "resize" {
 }
 bindsym $mod+r mode "resize"
 
+# change theme mode
+set $mode_theme theme (d)ark | (l)ight
+mode "$mode_theme" {
+        bindsym d exec change-theme dark,  mode "default"
+        bindsym l exec change-theme light, mode "default"
+        bindsym Return mode "default"
+        bindsym Escape mode "default"
+        bindsym q      mode "default"
+}
+bindsym $mod+t mode "$mode_theme"
+
 # application-specific window configurations
 for_window [class="mpv"] floating enable
 for_window [class="Mumble"] floating enable
diff --git a/.local/bin/change-theme b/.local/bin/change-theme
new file mode 100755 (executable)
index 0000000..5d997cd
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+dark_color='black' # #222
+light_color='white'
+
+if [ "$1" = "dark" ]; then
+    fg="$light_color"
+    bg="$dark_color"
+elif [ "$1" = "light" ]; then
+    fg="$dark_color"
+    bg="$light_color"
+else
+    echo "Usage: $0 {dark|light}"
+    exit 1
+fi
+
+# most applications using xresources
+printf "*.foreground: $fg\n*.background: $bg" | xrdb -override
+# xterm, basically
+printf "*VT100*foreground: $fg\n*VT100*background: $bg" | xrdb -override
+
+# emacs
+emacsclient -ue "(set-face-attribute 'default nil :foreground \"$fg\" :background \"$bg\")"
+# terminals
+for term in /dev/pts/*; do
+    if [ -w "$term" ]; then
+        printf "\033]10;$fg\a" > "$term"
+        printf "\033]11;$bg\a" > "$term"
+    fi
+done