Skip to content

Commit

Permalink
Fix regression from dual-line status bar feature (#382)
Browse files Browse the repository at this point in the history
* Use status-left/status-right again for default one-line
  status bar
* Use tmux default status-format setting for dual-line status
  bar feature, just split to separate lines for window-status
  and status-left/status-right

fixes #381
  • Loading branch information
xx4h authored Apr 2, 2024
1 parent 62f58f0 commit c7b13f8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions config/defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ export TMUX_POWERLINE_WINDOW_STATUS_SEPARATOR_DEFAULT=""

export TMUX_POWERLINE_MUTE_LEFT_KEYBINDING_DEFAULT=
export TMUX_POWERLINE_MUTE_RIGHT_KEYBINDING_DEFAULT=

# default tmux status-format, retrieve with:
# tmux set-option -gu status-format
# tmux show-option -g status-format
export TMUX_POWERLINE_STATUS_FORMAT_WINDOW_DEFAULT="#[list=on align=#{status-justify}]#[list=left-marker]<#[list=right-marker]>#[list=on]#{W:#[range=window|#{window_index} #{E:window-status-style}#{?#{&&:#{window_last_flag},#{!=:#{E:window-status-last-style},default}}, #{E:window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{E:window-status-bell-style},default}}, #{E:window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{E:window-status-activity-style},default}}, #{E:window-status-activity-style},}}]#[push-default]#{T:window-status-format}#[pop-default]#[norange default]#{?window_end_flag,,#{window-status-separator}},#[range=window|#{window_index} list=focus #{?#{!=:#{E:window-status-current-style},default},#{E:window-status-current-style},#{E:window-status-style}}#{?#{&&:#{window_last_flag},#{!=:#{E:window-status-last-style},default}}, #{E:window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{E:window-status-bell-style},default}}, #{E:window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{E:window-status-activity-style},default}}, #{E:window-status-activity-style},}}]#[push-default]#{T:window-status-current-format}#[pop-default]#[norange list=on default]#{?window_end_flag,,#{window-status-separator}}}"
export TMUX_POWERLINE_STATUS_FORMAT_LEFT_DEFAULT="#[align=left range=left #{E:status-left-style}]#[push-default]#{T;=/#{status-left-length}:status-left}#[pop-default]#[norange default]"
export TMUX_POWERLINE_STATUS_FORMAT_RIGHT_DEFAULT="#[nolist align=right range=right #{E:status-right-style}]#[push-default]#{T;=/#{status-right-length}:status-right}#[pop-default]#[norange default]"
12 changes: 12 additions & 0 deletions lib/config_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ process_settings() {
export TMUX_POWERLINE_MUTE_RIGHT_KEYBINDING="${TMUX_POWERLINE_MUTE_RIGHT_KEYBINDING_DEFAULT}"
fi

if [ -z "$TMUX_POWERLINE_STATUS_FORMAT_WINDOW" ]; then
export TMUX_POWERLINE_STATUS_FORMAT_WINDOW="${TMUX_POWERLINE_STATUS_FORMAT_WINDOW}"
fi

if [ -z "$TMUX_POWERLINE_STATUS_FORMAT_LEFT" ]; then
export TMUX_POWERLINE_STATUS_FORMAT_LEFT="${TMUX_POWERLINE_STATUS_FORMAT_LEFT}"
fi

if [ -z "$TMUX_POWERLINE_STATUS_FORMAT_RIGHT" ]; then
export TMUX_POWERLINE_STATUS_FORMAT_RIGHT="${TMUX_POWERLINE_STATUS_FORMAT_RIGHT}"
fi

eval TMUX_POWERLINE_DIR_USER_SEGMENTS="$TMUX_POWERLINE_DIR_USER_SEGMENTS"
eval TMUX_POWERLINE_DIR_USER_THEMES="$TMUX_POWERLINE_DIR_USER_THEMES"
if [ -n "$TMUX_POWERLINE_DIR_USER_THEMES" ] && [ -f "${TMUX_POWERLINE_DIR_USER_THEMES}/${TMUX_POWERLINE_THEME}.sh" ]; then
Expand Down
19 changes: 11 additions & 8 deletions main.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export TMUX_POWERLINE_DIR_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
source "${TMUX_POWERLINE_DIR_HOME}/lib/headers.sh"
process_settings

# Apply default status-format to ensure default single-line status bar is working as
# expected, especially when switching from dual-line status-bar.
tmux set-option -gu status-format

# Configure tmux to use tmux-powerline.
# It's assumed that this will override these setting if already set in tmux.conf, as TPM is recommended to be loaded last in the tmux.conf. Ref: https://github.com/tmux-plugins/tpm
tmux set-option -g status "$TMUX_POWERLINE_STATUS_VISIBILITY"
Expand All @@ -21,11 +25,10 @@ tmux set-option -g message-style "$TMUX_POWERLINE_STATUS_STYLE"
tmux set-option -g status-left-length $TMUX_POWERLINE_STATUS_LEFT_LENGTH
tmux set-option -g status-right-length $TMUX_POWERLINE_STATUS_RIGHT_LENGTH

if [ "$TMUX_POWERLINE_STATUS_VISIBILITY" = "on" ]; then
tmux set-option -g status-format[0] "#[align=left]#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh left)"
tmux set-option -ag status-format[0] "#[align=centre]#{W:#{E:window-status-format} ,#{E:window-status-current-format} }"
tmux set-option -ag status-format[0] "#[align=right]#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh right)"
elif [ "$TMUX_POWERLINE_STATUS_VISIBILITY" = "2" ]; then
tmux set-option -g status-left "#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh left)"
tmux set-option -g status-right "#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh right)"

if [ "$TMUX_POWERLINE_STATUS_VISIBILITY" = "2" ]; then
# handle TMUX_POWERLINE_WINDOW_STATUS_LINE=0 and fallback for misconfiguration
if [ "$TMUX_POWERLINE_WINDOW_STATUS_LINE" != "1" ]; then
window_status=0
Expand All @@ -34,9 +37,9 @@ elif [ "$TMUX_POWERLINE_STATUS_VISIBILITY" = "2" ]; then
window_status=1
left_right_status=0
fi
tmux set-option -g status-format[$window_status] "#[align=centre]#{W:#{E:window-status-format} ,#{E:window-status-current-format} }"
tmux set-option -g status-format[$left_right_status] "#[align=left]#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh left)"
tmux set-option -ag status-format[$left_right_status] "#[align=right]#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh right)"
tmux set-option -g status-format[$window_status] "${TMUX_POWERLINE_STATUS_FORMAT_WINDOW:-${TMUX_POWERLINE_STATUS_FORMAT_WINDOW_DEFAULT}}"
tmux set-option -g status-format[$left_right_status] "${TMUX_POWERLINE_STATUS_FORMAT_LEFT:-${TMUX_POWERLINE_STATUS_FORMAT_LEFT_DEFAULT}}"
tmux set-option -ag status-format[$left_right_status] "${TMUX_POWERLINE_STATUS_FORMAT_RIGHT:-${TMUX_POWERLINE_STATUS_FORMAT_RIGHT_DEFAULT}}"
fi

tmux set-option -g window-status-current-format "#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh window-current-format)"
Expand Down

0 comments on commit c7b13f8

Please sign in to comment.