Skip to content

Commit abdf080

Browse files
authored
Merge pull request #362 from izzygomez/izzygomez/fix-powerline-window-status
Fix tmux-powerline window status elements rendering & updating.
2 parents 302023c + c932f78 commit abdf080

File tree

11 files changed

+74
-64
lines changed

11 files changed

+74
-64
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ Drew Daniels <[email protected]>
4242
Danfeng Shan <[email protected]>
4343
Abraham Nuñez <[email protected]>
4444
Gavin Kondrath <[email protected]>
45+
Izzy Gomez <[email protected]>

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,6 @@ tmux source-file ~/.tmux.conf
220220
### Multiple lines in bash or no powerline in zsh using iTerm (macOS)
221221
If your tmux looks like [this](https://github.com/erikw/tmux-powerline/issues/125) then you may have to in iTerm uncheck [Unicode East Asian Ambiguous characters are wide] in Preferences -> Settings -> Advanced.
222222

223-
224-
### Changing the theme variables does not have effect
225-
After changing the theme's settings e.g.
226-
* `TMUX_POWERLINE_DEFAULT_*GROUND_COLOR`
227-
* `TMUX_POWERLINE_WINDOW_STATUS_FORMAT`
228-
* etc.
229-
230-
nothing happens.
231-
232-
This is a known issue, see #322 & #336 for details. Workaround: reload the theme change by creating a new tmux session.
233-
234223
# Hacking
235224
This project can only gain positively from contributions. Fork today and make your own enhancements and segments to share back! If you'd like, add your name and E-mail to AUTHORS before making a pull request so you can get some credit for your work :-)
236225

config/defaults.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ export TMUX_POWERLINE_STATUS_JUSTIFICATION_DEFAULT="centre"
1111
export TMUX_POWERLINE_STATUS_LEFT_LENGTH_DEFAULT=60
1212
export TMUX_POWERLINE_STATUS_RIGHT_LENGTH_DEFAULT=90
1313

14+
export TMUX_POWERLINE_WINDOW_STATUS_SEPARATOR_DEFAULT=""
15+
1416
export TMUX_POWERLINE_MUTE_LEFT_KEYBINDING_DEFAULT=
1517
export TMUX_POWERLINE_MUTE_RIGHT_KEYBINDING_DEFAULT=

lib/arg_processing.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#! Check script arguments.
22

3-
check_arg_side() {
4-
local side="$1"
5-
if ! [[ "$side" == "left" || "$side" == "right" || "$side" == "init" ]]; then
6-
echo "Argument must be the side to handle {left, right} or {init} and not \"${side}\"."
3+
check_arg_segment() {
4+
local segment="$1"
5+
if ! [[ "$segment" == "left" || "$segment" == "right" || "$segment" == "window-current-format" || "$segment" == "window-format" ]]; then
6+
echo "Argument must be the side to handle {left, right}, or {window-current-format, window-format}, not \"${segment}\"."
77
exit 1
88
fi
99
}

lib/config_file.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ process_settings() {
3535
export TMUX_POWERLINE_STATUS_RIGHT_LENGTH="${TMUX_POWERLINE_STATUS_RIGHT_LENGTH_DEFAULT}"
3636
fi
3737

38+
if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_SEPARATOR" ]; then
39+
export TMUX_POWERLINE_WINDOW_STATUS_SEPARATOR="${TMUX_POWERLINE_WINDOW_STATUS_SEPARATOR_DEFAULT}"
40+
fi
41+
3842
if [ -z "$TMUX_POWERLINE_MUTE_LEFT_KEYBINDING" ]; then
3943
export TMUX_POWERLINE_MUTE_LEFT_KEYBINDING="${TMUX_POWERLINE_MUTE_LEFT_KEYBINDING_DEFAULT}"
4044
fi
@@ -51,6 +55,18 @@ process_settings() {
5155
source "${TMUX_POWERLINE_DIR_THEMES}/${TMUX_POWERLINE_THEME}.sh"
5256
fi
5357

58+
# Set the default status bar colors to the theme's default colors. This section is here because it needs to be after the theme is sourced.
59+
if [ -z "$TMUX_POWERLINE_STATUS_STYLE" ]; then
60+
local bg_color
61+
local fg_color
62+
63+
fg_color=$(__normalize_color "$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR")
64+
bg_color=$(__normalize_color "$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR")
65+
66+
export TMUX_POWERLINE_STATUS_STYLE="fg=$fg_color,bg=$bg_color"
67+
fi
68+
69+
5470
}
5571

5672
generate_default_config() {
@@ -87,6 +103,9 @@ generate_default_config() {
87103
# The maximum length of the right status bar.
88104
export TMUX_POWERLINE_STATUS_RIGHT_LENGTH="${TMUX_POWERLINE_STATUS_RIGHT_LENGTH_DEFAULT}"
89105
106+
# The separator to use between windows on the status bar.
107+
export TMUX_POWERLINE_WINDOW_STATUS_SEPARATOR=""
108+
90109
# Uncomment these if you want to enable tmux bindings for muting (hiding) one of the status bars.
91110
# E.g. this example binding would mute the left status bar when pressing <prefix> followed by Ctrl-[
92111
#export TMUX_POWERLINE_MUTE_LEFT_KEYBINDING="C-["

lib/powerline.sh

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Library functions
22

3-
print_powerline() {
3+
print_powerline_side() {
44
local side="$1"
55
local upper_side
66

@@ -18,28 +18,7 @@ print_powerline() {
1818
__process_powerline
1919
}
2020

21-
format() {
22-
local type="$1"
23-
local bg_color
24-
local fg_color
25-
26-
bg_color=$(__normalize_color "$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR")
27-
fg_color=$(__normalize_color "$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR")
28-
29-
case $type in
30-
inverse)
31-
echo "fg=$bg_color,bg=$fg_color,nobold,noitalics,nounderscore"
32-
;;
33-
regular)
34-
echo "fg=$fg_color,bg=$bg_color,nobold,noitalics,nounderscore"
35-
;;
36-
*)
37-
;;
38-
esac
39-
}
40-
41-
# Prettifies the window-status segments.
42-
init_powerline() {
21+
print_powerline_window_status_current_format() {
4322
if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_CURRENT" ]; then
4423
TMUX_POWERLINE_WINDOW_STATUS_CURRENT=(
4524
"#[$(format inverse)]" \
@@ -52,12 +31,10 @@ init_powerline() {
5231
)
5332
fi
5433

55-
if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_STYLE" ]; then
56-
TMUX_POWERLINE_WINDOW_STATUS_STYLE=(
57-
"$(format regular)"
58-
)
59-
fi
34+
printf '%s' "${TMUX_POWERLINE_WINDOW_STATUS_CURRENT[@]}"
35+
}
6036

37+
print_powerline_window_status_format() {
6138
if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_FORMAT" ]; then
6239
TMUX_POWERLINE_WINDOW_STATUS_FORMAT=(
6340
"#[$(format regular)]" \
@@ -67,16 +44,27 @@ init_powerline() {
6744
)
6845
fi
6946

47+
printf '%s' "${TMUX_POWERLINE_WINDOW_STATUS_FORMAT[@]}"
48+
}
49+
50+
format() {
51+
local type="$1"
7052
local bg_color
7153
local fg_color
7254

7355
bg_color=$(__normalize_color "$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR")
7456
fg_color=$(__normalize_color "$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR")
7557

76-
tmux set-option -g window-status-current-format "$(printf '%s' "${TMUX_POWERLINE_WINDOW_STATUS_CURRENT[@]}")"
77-
tmux set-option -g window-status-format "$(printf '%s' "${TMUX_POWERLINE_WINDOW_STATUS_FORMAT[@]}")"
78-
tmux set-option -g window-status-style "$(printf '%s' "${TMUX_POWERLINE_WINDOW_STATUS_STYLE[@]}")"
79-
tmux set-option -g status-style "fg=$fg_color,bg=$bg_color"
58+
case $type in
59+
inverse)
60+
echo "fg=$bg_color,bg=$fg_color,nobold,noitalics,nounderscore"
61+
;;
62+
regular)
63+
echo "fg=$fg_color,bg=$bg_color,nobold,noitalics,nounderscore"
64+
;;
65+
*)
66+
;;
67+
esac
8068
}
8169

8270
__process_segment_defaults() {

main.tmux

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ process_settings
1515
tmux set-option -g status "$TMUX_POWERLINE_STATUS_VISIBILITY"
1616
tmux set-option -g status-interval "$TMUX_POWERLINE_STATUS_INTERVAL"
1717
tmux set-option -g status-justify "$TMUX_POWERLINE_STATUS_JUSTIFICATION"
18+
tmux set-option -g status-style "$TMUX_POWERLINE_STATUS_STYLE"
1819

1920
tmux set-option -g status-left-length $TMUX_POWERLINE_STATUS_LEFT_LENGTH
2021
tmux set-option -g status-right-length $TMUX_POWERLINE_STATUS_RIGHT_LENGTH
2122

2223
tmux set-option -g status-left "#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh left)"
2324
tmux set-option -g status-right "#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh right)"
2425

26+
tmux set-option -g window-status-current-format "#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh window-current-format)"
27+
tmux set-option -g window-status-format "#(${TMUX_POWERLINE_DIR_HOME}/powerline.sh window-format)"
28+
tmux set-option -g window-status-separator "$TMUX_POWERLINE_WINDOW_STATUS_SEPARATOR"
29+
2530
if [ -n "$TMUX_POWERLINE_MUTE_LEFT_KEYBINDING" ]; then
2631
tmux bind "$TMUX_POWERLINE_MUTE_LEFT_KEYBINDING" run "$TMUX_POWERLINE_DIR_HOME/mute_powerline.sh left"
2732
fi
2833

2934
if [ -n "$TMUX_POWERLINE_MUTE_RIGHT_KEYBINDING" ]; then
3035
tmux bind "$TMUX_POWERLINE_MUTE_RIGHT_KEYBINDING" run "$TMUX_POWERLINE_DIR_HOME/mute_powerline.sh right"
3136
fi
32-
33-
tmux set-hook -g session-created "run-shell '${TMUX_POWERLINE_DIR_HOME}/powerline.sh init'"

mute_powerline.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ source "${TMUX_POWERLINE_DIR_LIB}/muting.sh"
77
source "${TMUX_POWERLINE_DIR_LIB}/arg_processing.sh"
88

99
side="$1"
10-
check_arg_side "$side"
10+
check_arg_segment "$side"
1111
toggle_powerline_mute_status "$side"

powerline.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ source "${TMUX_POWERLINE_DIR_HOME}/lib/headers.sh"
66

77
if ! powerline_muted "$1"; then
88
process_settings
9-
check_arg_side "$1"
10-
if [ $1 == "init" ]; then
11-
init_powerline
9+
check_arg_segment "$1"
10+
if [ $1 == "window-current-format" ]; then
11+
print_powerline_window_status_current_format
12+
elif [ $1 == "window-format" ]; then
13+
print_powerline_window_status_format
1214
else
13-
print_powerline "$1"
15+
print_powerline_side "$1"
1416
fi
1517
fi
1618

themes/bubble.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD=""
5757
TMUX_POWERLINE_SEPARATOR_RIGHT_THIN=""
5858
TMUX_POWERLINE_SEPARATOR_THIN="|"
5959

60+
# See Color formatting section below for details on what colors can be used here.
6061
TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR=${TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR:-$thm_bg}
6162
TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR=${TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR:-$thm_fg}
6263
TMUX_POWERLINE_SEG_AIR_COLOR=$("${TMUX_POWERLINE_DIR_HOME}/segments/air_color.sh")
6364

6465
TMUX_POWERLINE_DEFAULT_LEFTSIDE_SEPARATOR=${TMUX_POWERLINE_DEFAULT_LEFTSIDE_SEPARATOR:-$TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD}
6566
TMUX_POWERLINE_DEFAULT_RIGHTSIDE_SEPARATOR=${TMUX_POWERLINE_DEFAULT_RIGHTSIDE_SEPARATOR:-$TMUX_POWERLINE_SEPARATOR_LEFT_BOLD}
6667

67-
# See man tmux.conf for additional formatting options for the status line.
68+
# See `man tmux` for additional formatting options for the status line.
6869
# The `format regular` and `format inverse` functions are provided as conveinences
6970

7071
if [ -z $TMUX_POWERLINE_WINDOW_STATUS_CURRENT ]; then
@@ -97,10 +98,12 @@ fi
9798

9899
# Format: segment_name background_color foreground_color [non_default_separator] [separator_background_color] [separator_foreground_color] [spacing_disable] [separator_disable]
99100
#
100-
# * background_color and foreground_color. Formats:
101-
# * Named colors (chech man page of tmux for complete list) e.g. black, red, green, yellow, blue, magenta, cyan, white
102-
# * a hexadecimal RGB string e.g. #ffffff
103-
# * 'default' for the defalt tmux color.
101+
# * background_color and foreground_color. Color formatting (see `man tmux` for complete list):
102+
# * Named colors, e.g. black, red, green, yellow, blue, magenta, cyan, white
103+
# * Hexadecimal RGB string e.g. #ffffff
104+
# * 'default' for the default tmux color.
105+
# * 'terminal' for the terminal's default background/foreground color
106+
# * The numbers 0-255 for the 256-color palette. Run `tmux-powerline/color-palette.sh` to see the colors.
104107
# * non_default_separator - specify an alternative character for this segment's separator
105108
# * separator_background_color - specify a unique background color for the separator
106109
# * separator_foreground_color - specify a unique foreground color for the separator

0 commit comments

Comments
 (0)