From feef9a9d6d60924135be776d8519ee5d91c82076 Mon Sep 17 00:00:00 2001 From: technofab Date: Tue, 17 Jun 2025 12:14:40 +0200 Subject: [PATCH] feat: add mode indicator --- scripts/mode.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/tmux2k.sh | 18 ++++++++++++------ 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100755 scripts/mode.sh diff --git a/scripts/mode.sh b/scripts/mode.sh new file mode 100755 index 0000000..23fa7f0 --- /dev/null +++ b/scripts/mode.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$current_dir"/utils.sh + +# Define styles +STYLE_COPY="#[bg=black,fg=#ffff00]" +STYLE_PREFIX="#[bg=black,fg=#00ee00]" +STYLE_SYNC="#[bg=black,fg=#ff0000]" +STYLE_KNOWN_TABLE="#[bg=black,fg=#00aaff]" +STYLE_TABLE="#[bg=black,fg=#0066ff]" +STYLE_NORMAL="#[bg=black,fg=red]" + +main() { + # Get active client and active pane for it + active_client=$(tmux display -p '#{client_tty}') + active_pane=$(tmux list-panes -a -F '#{pane_active} #{pane_tty} #{pane_id}' | \ + awk -v tty="$active_client" '$1 == "1" && $2 == tty { print $3 }') + + # Check states relative to that pane + pane_in_mode=$(tmux display -p -t "$active_pane" '#{pane_in_mode}') + client_prefix=$(tmux display -p '#{client_prefix}') + pane_sync=$(tmux display -p -t "$active_pane" '#{pane_synchronized}') + key_table=$(tmux display -p '#{client_key_table}') + + # Mode priority logic + if [ "$pane_in_mode" = "1" ]; then + echo "${STYLE_COPY} COPY #[default]" + elif [ "$key_table" != "root" ] && [ "$key_table" != "prefix" ]; then + if [ "$key_table" = "resize" ]; then + echo "${STYLE_KNOWN_TABLE} RESIZE #[default]" + elif [ "$key_table" = "cpyrt" ]; then + echo "${STYLE_KNOWN_TABLE} RAT #[default]" + else + echo "${STYLE_TABLE} TABLE:$key_table #[default]" + fi + elif [ "$client_prefix" = "1" ]; then + echo "${STYLE_PREFIX} PREFIX #[default]" + elif [ "$pane_sync" = "1" ]; then + echo "${STYLE_SYNC} SYNC #[default]" + else + echo "${STYLE_NORMAL} TMUX #[default]" + fi +} + +main + diff --git a/scripts/tmux2k.sh b/scripts/tmux2k.sh index 5b92fa4..20c7a99 100755 --- a/scripts/tmux2k.sh +++ b/scripts/tmux2k.sh @@ -49,7 +49,8 @@ declare -A plugin_colors=( ["time"]="light_blue text" ["pomodoro"]="red text" ["window"]="bg_main blue" - ["current"]="bg_main blue" + ["current"]="green text" + ["mode"]="duo_bg blue" ) get_plugin_colors() { @@ -167,7 +168,8 @@ set_theme() { ["time"]="text light_blue" ["pomodoro"]="text red" ["window"]="blue bg_main" - ["current"]="blue bg_main" + ["current"]="text red" + ["mode"]="blue bg_main" ) fi } @@ -206,6 +208,10 @@ status_bar() { IFS=' ' read -r -a colors <<<"$(get_plugin_colors "$plugin")" script="#($current_dir/$plugin.sh)" + # the mode module adds it's own spaces + if [ "$plugin" != "mode" ]; then + script=" $script " + fi if [ "$side" == "left" ]; then if $show_powerline; then @@ -213,18 +219,18 @@ status_bar() { IFS=' ' read -r -a next_colors <<<"$(get_plugin_colors "$next_plugin")" pl_bg=${!next_colors[0]:-$bg_main} tmux set-option -ga status-left \ - "#[fg=${!colors[1]},bg=${!colors[0]}] $script #[fg=${!colors[0]},bg=${pl_bg},nobold,nounderscore,noitalics]${l_sep}" + "#[fg=${!colors[1]},bg=${!colors[0]}]$script#[fg=${!colors[0]},bg=${pl_bg},nobold,nounderscore,noitalics]${l_sep}" pl_bg=${bg_main} else - tmux set-option -ga status-left "#[fg=${!colors[1]},bg=${!colors[0]}] $script " + tmux set-option -ga status-left "#[fg=${!colors[1]},bg=${!colors[0]}]$script" fi else if $show_powerline; then tmux set-option -ga status-right \ - "#[fg=${!colors[0]},bg=${pl_bg},nobold,nounderscore,noitalics]${r_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " + "#[fg=${!colors[0]},bg=${pl_bg},nobold,nounderscore,noitalics]${r_sep}#[fg=${!colors[1]},bg=${!colors[0]}]$script" pl_bg=${!colors[0]} else - tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script " + tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}]$script" fi fi done