|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +mode_indicator_placeholder="\#{tmux_mode_indicator}" |
| 6 | + |
| 7 | +prefix_prompt_config='@mode_indicator_prefix_prompt' |
| 8 | +copy_prompt_config='@mode_indicator_copy_prompt' |
| 9 | +sync_prompt_config='@mode_indicator_sync_prompt' |
| 10 | +empty_prompt_config='@mode_indicator_empty_prompt' |
| 11 | +prefix_mode_style_config='@mode_indicator_prefix_mode_style' |
| 12 | +copy_mode_style_config='@mode_indicator_copy_mode_style' |
| 13 | +sync_mode_style_config='@mode_indicator_sync_mode_style' |
| 14 | +empty_mode_style_config='@mode_indicator_empty_mode_style' |
| 15 | + |
| 16 | +tmux_option() { |
| 17 | + local -r option=$(tmux show-option -gqv "$1") |
| 18 | + local -r fallback="$2" |
| 19 | + echo "${option:-$fallback}" |
| 20 | +} |
| 21 | + |
| 22 | +indicator_style() { |
| 23 | + local -r style=$(tmux_option "$1" "$2") |
| 24 | + echo "${style:+#[${style/,/]#[}]}" |
| 25 | +} |
| 26 | + |
| 27 | +init_tmux_mode_indicator() { |
| 28 | + local -r \ |
| 29 | + prefix_prompt=$(tmux_option "$prefix_prompt_config" " WAIT ") \ |
| 30 | + copy_prompt=$(tmux_option "$copy_prompt_config" " COPY ") \ |
| 31 | + sync_prompt=$(tmux_option "$sync_prompt_config" " SYNC ") \ |
| 32 | + empty_prompt=$(tmux_option "$empty_prompt_config" " TMUX ") \ |
| 33 | + prefix_style=$(indicator_style "$prefix_mode_style_config" "bg=blue,fg=black") \ |
| 34 | + copy_style=$(indicator_style "$copy_mode_style_config" "bg=yellow,fg=black") \ |
| 35 | + sync_style=$(indicator_style "$sync_mode_style_config" "bg=red,fg=black") \ |
| 36 | + empty_style=$(indicator_style "$empty_mode_style_config" "bg=cyan,fg=black") |
| 37 | + |
| 38 | + local -r \ |
| 39 | + mode_prompt="#{?client_prefix,$prefix_prompt,#{?pane_in_mode,$copy_prompt,#{?pane_synchronized,$sync_prompt,$empty_prompt}}}" \ |
| 40 | + mode_style="#{?client_prefix,$prefix_style,#{?pane_in_mode,$copy_style,#{?pane_synchronized,$sync_style,$empty_style}}}" |
| 41 | + |
| 42 | + local -r mode_indicator="#[default]$mode_style$mode_prompt#[default]" |
| 43 | + |
| 44 | + local -r status_left_value="$(tmux_option "status-left")" |
| 45 | + tmux set-option -gq "status-left" "${status_left_value/$mode_indicator_placeholder/$mode_indicator}" |
| 46 | + |
| 47 | + local -r status_right_value="$(tmux_option "status-right")" |
| 48 | + tmux set-option -gq "status-right" "${status_right_value/$mode_indicator_placeholder/$mode_indicator}" |
| 49 | +} |
| 50 | + |
| 51 | +init_tmux_mode_indicator |
0 commit comments