From 68b8a7b608d1a6896e05b21a111f94e0a129a4f0 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Thu, 24 Jul 2025 00:40:02 +0200 Subject: [PATCH] Setup seamless, automatic, and persistent colorscheme switching in tmux that follows colorsync --- tmux/tmux-status-right.sh | 30 ++++++++++++++++++++--- tmux/tmux-statusbar-color.sh | 28 +++++++++++++++++++++ tmux/tmux-watchman-statuscolor-trigger.sh | 4 +++ tmux/tmux.conf | 8 +++--- 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100755 tmux/tmux-statusbar-color.sh create mode 100755 tmux/tmux-watchman-statuscolor-trigger.sh diff --git a/tmux/tmux-status-right.sh b/tmux/tmux-status-right.sh index 2882de3..33ed983 100755 --- a/tmux/tmux-status-right.sh +++ b/tmux/tmux-status-right.sh @@ -1,7 +1,31 @@ -format_for_tmux() { - fg="#1F2430" - bg="#73D0FF" +THEME=$(colorsync get) + +default() { + bg="#95E6CB" + fg="#000000" + text_col="#BFBDB6" +} + +case "$THEME" in + ayudark) + default + ;; + ayumirage) + bg="#95E6CB" + fg="#101521" text_col="#CCCAC2" + ;; + ayulight) + bg="#4CBF99" + fg="#F3F4F5" + text_col="#5C6166" + ;; + *) + default + ;; +esac + +format_for_tmux() { echo $1 | gawk -v bg="$bg" -v fg="$fg" -v text_col="$text_col" '{printf("#[default]#[fg="bg"]#[default]#[bg="bg", fg="fg", bold]%s #[default]#[fg="bg"]#[default]#[fg="text_col"] %s", substr($0, 1, 1), substr($0, 2))}' } diff --git a/tmux/tmux-statusbar-color.sh b/tmux/tmux-statusbar-color.sh new file mode 100755 index 0000000..b24f216 --- /dev/null +++ b/tmux/tmux-statusbar-color.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +THEME=$(colorsync get) + +default() { + tmux set-option -g status-bg "#000000" + tmux setw -g window-status-format "#[bg=#000000,fg=#BFBDB6] #[bold]#I #[default] #[fg=#59C2FF]#W #[default]" + tmux setw -g window-status-current-format "#[bg=#95E6CB,fg=#000000] #[bold]#I #[default] #[fg=#FF8F40]#W #[default]" +} + +case "$THEME" in + ayudark) + default + ;; + ayumirage) + tmux set-option -g status-bg "#101521" + tmux setw -g window-status-format "#[bg=#101521,fg=#CCCAC2] #[bold]#I #[default] #[fg=#73D0FF]#W #[default]" + tmux setw -g window-status-current-format "#[bg=#95E6CB,fg=#101521] #[bold]#I #[default] #[fg=#FFCC66]#W #[default]" + ;; + ayulight) + tmux set-option -g status-bg "#F0F0F0" + tmux setw -g window-status-format "#[bg=#F0F0F0,fg=#5C6166] #[bold]#I #[default] #[fg=#399EE6]#W #[default]" + tmux setw -g window-status-current-format "#[bg=#4CBF99,fg=#F0F0F0] #[bold]#I #[default] #[fg=#FA8D3E]#W #[default]" + ;; + *) + default + ;; +esac diff --git a/tmux/tmux-watchman-statuscolor-trigger.sh b/tmux/tmux-watchman-statuscolor-trigger.sh new file mode 100755 index 0000000..80d3a5f --- /dev/null +++ b/tmux/tmux-watchman-statuscolor-trigger.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +watchman watch-project "$HOME/.local/state/colorsync" +watchman -- trigger "$HOME/.local/state/colorsync" tmux_statusbar_color 'current' -- bash "$HOME/.config/tmux/tmux-statusbar-color.sh" diff --git a/tmux/tmux.conf b/tmux/tmux.conf index edb3948..25eb8a2 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -107,7 +107,7 @@ set -g history-limit 50000 set -g display-time 2500 # Refresh 'status-left' and 'status-right' more often, from every 15s to 5s -set -g status-interval 2 +set -g status-interval 5 # Focus events enabled for terminals that support them set -g focus-events on @@ -121,13 +121,11 @@ setw -g automatic-rename off set-hook -g after-new-window "run-shell '~/.config/tmux/tmux-rename-window.sh | xargs tmux rename-window'" set-hook -g pane-focus-in "run-shell '~/.config/tmux/tmux-rename-window.sh | xargs tmux rename-window'" -setw -g window-status-format "#[bg=#171B24,fg=#CCCAC2] #[bold]#I #[default] #[fg=#73D0FF]#W #[default]" -setw -g window-status-current-format "#[bg=#757B84,fg=#EFEDE7] #[bold]#I #[default] #[fg=#FFAD66]#W #[default]" - # Set the right status: Battery, date and time, session name set -g status-right "#($HOME/.config/tmux/tmux-status-right.sh)" +run-shell '~/.config/tmux/tmux-statusbar-color.sh' +run-shell '~/.config/tmux/tmux-watchman-statuscolor.sh' -set -g status-bg "#171B24" set -g status-style bold # SSH agent forwarding