Skip to content

Commit 29143d8

Browse files
authored
Fix segment separator color settings (#427)
* introduce defaults for all segment config options * fix actual usage of separator_background_color and separator_foreground_color * document defaults in themes fixes #426
1 parent 14dcda0 commit 29143d8

File tree

3 files changed

+82
-29
lines changed

3 files changed

+82
-29
lines changed

lib/powerline.sh

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ __process_segment_defaults() {
7272
for segment_index in "${!input_segments[@]}"; do
7373
local input_segment
7474
read -r -a input_segment <<<"${input_segments[segment_index]}"
75-
eval "local default_separator=\$TMUX_POWERLINE_DEFAULT_${upper_side}SIDE_SEPARATOR"
7675

7776
powerline_segment_with_defaults=(
7877
"${input_segment[0]:-no_script}"
79-
"${input_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}"
80-
"${input_segment[2]:-$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR}"
81-
"${input_segment[3]:-$default_separator}"
82-
"${input_segment[6]:-$spacing_disable}"
83-
"${input_segment[7]:-$separator_disable}"
78+
"${input_segment[1]:-default_bg_color}"
79+
"${input_segment[2]:-default_fg_color}"
80+
"${input_segment[3]:-default_separator}"
81+
"${input_segment[4]:-no_sep_bg_color}"
82+
"${input_segment[5]:-no_sep_fg_color}"
83+
"${input_segment[6]:-no_spacing_disable}"
84+
"${input_segment[7]:-no_separator_disable}"
8485
)
8586

8687
powerline_segments[segment_index]="${powerline_segment_with_defaults[*]}"
@@ -115,11 +116,11 @@ __process_scripts() {
115116
fi
116117

117118
if [ -n "$output" ]; then
118-
if [[ ${powerline_segment[4]} == "left_disable" ]]; then
119+
if [[ ${powerline_segment[6]} == "left_disable" ]]; then
119120
powerline_segment_contents[segment_index]="$output "
120-
elif [[ ${powerline_segment[4]} == "right_disable" ]]; then
121+
elif [[ ${powerline_segment[6]} == "right_disable" ]]; then
121122
powerline_segment_contents[segment_index]=" $output"
122-
elif [[ ${powerline_segment[4]} == "both_disable" ]]; then
123+
elif [[ ${powerline_segment[6]} == "both_disable" ]]; then
123124
powerline_segment_contents[segment_index]="$output"
124125
else
125126
powerline_segment_contents[segment_index]=" $output "
@@ -134,28 +135,43 @@ __process_colors() {
134135
for segment_index in "${!powerline_segments[@]}"; do
135136
local powerline_segment
136137
read -r -a powerline_segment <<<"${powerline_segments[segment_index]}"
137-
local separator_enable=${powerline_segment[5]}
138+
local separator_enable=${powerline_segment[7]}
138139
# Find the next segment that produces content (i.e. skip empty segments).
139140
for next_segment_index in $(eval echo "{$((segment_index + 1))..${#powerline_segments}}"); do
140141
[[ -n ${powerline_segments[next_segment_index]} ]] && break
141142
done
142143
local next_segment
143144
read -r -a next_segment <<<"${powerline_segments[next_segment_index]}"
144145

146+
if [ "${powerline_segment[1]}" = "default_bg_color" ]; then
147+
powerline_segment[1]="$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR"
148+
fi
149+
if [ "${powerline_segment[2]}" = "default_fg_color" ]; then
150+
powerline_segment[2]="$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR"
151+
fi
152+
145153
if [ "$side" == 'left' ]; then
146-
powerline_segment[4]=${next_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
154+
if [ "${powerline_segment[4]}" = "no_sep_bg_color" ]; then
155+
powerline_segment[4]=${next_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
156+
fi
147157
elif [ "$side" == 'right' ]; then
148-
powerline_segment[4]=${previous_background_color:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
158+
if [ "${powerline_segment[4]}" = "no_sep_bg_color" ]; then
159+
powerline_segment[4]=${previous_background_color:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
160+
fi
149161
fi
150162

151163
if __segment_separator_is_thin; then
152-
powerline_segment[5]=${powerline_segment[2]}
164+
if [ "${powerline_segment[5]}" = "no_sep_fg_color" ]; then
165+
powerline_segment[5]=${powerline_segment[2]}
166+
fi
153167
else
154-
powerline_segment[5]=${powerline_segment[1]}
168+
if [ "${powerline_segment[5]}" = "no_sep_fg_color" ]; then
169+
powerline_segment[5]=${powerline_segment[1]}
170+
fi
155171
fi
156172

157173
local previous_background_color=${powerline_segment[1]}
158-
powerline_segment[6]=$separator_enable
174+
powerline_segment[7]=$separator_enable
159175

160176
powerline_segments[segment_index]="${powerline_segment[*]}"
161177
done
@@ -168,12 +184,21 @@ __process_powerline() {
168184

169185
local background_color=${powerline_segment[1]}
170186
local foreground_color=${powerline_segment[2]}
171-
local separator=${powerline_segment[3]}
187+
if [ "${powerline_segment[3]}" = "default_separator" ]; then
188+
if [ "$upper_side" = "RIGHT" ]; then
189+
local separator="$TMUX_POWERLINE_DEFAULT_RIGHTSIDE_SEPARATOR"
190+
elif [ "$upper_side" = "LEFT" ]; then
191+
local separator="$TMUX_POWERLINE_DEFAULT_LEFTSIDE_SEPARATOR"
192+
fi
193+
else
194+
local separator=${powerline_segment[3]}
195+
fi
172196
local separator_background_color=${powerline_segment[4]}
173197
local separator_foreground_color=${powerline_segment[5]}
174-
local separator_disable=${powerline_segment[6]}
198+
local spacing_disable=${powerline_segment[6]}
199+
local separator_disable=${powerline_segment[7]}
175200

176-
eval "__print_${side}_segment \"${segment_index}\" \"${background_color}\" \"${foreground_color}\" \"${separator}\" \"${separator_background_color}\" \"${separator_foreground_color}\" \"${separator_disable}\""
201+
eval "__print_${side}_segment \"${segment_index}\" \"${background_color}\" \"${foreground_color}\" \"${separator}\" \"${separator_background_color}\" \"${separator_foreground_color}\" \"${spacing_disable}\" \"${separator_disable}\""
177202
done
178203
}
179204

@@ -184,7 +209,8 @@ __print_left_segment() {
184209
local separator=$4
185210
local separator_background_color=$5
186211
local separator_foreground_color=$6
187-
local separator_disable=$7
212+
local spacing_disable=$7
213+
local separator_disable=$8
188214

189215
__print_colored_content "$content" "$content_background_color" "$content_foreground_color"
190216
if [ ! "$separator_disable" == "separator_disable" ]; then
@@ -199,7 +225,8 @@ __print_right_segment() {
199225
local separator=$4
200226
local separator_background_color=$5
201227
local separator_foreground_color=$6
202-
local separator_disable=$7
228+
local spacing_disable=$7
229+
local separator_disable=$8
203230

204231
if [ ! "$separator_disable" == "separator_disable" ]; then
205232
__print_colored_content "$separator" "$separator_background_color" "$separator_foreground_color"

themes/bubble.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,46 @@ if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_FORMAT" ]; then
9999
)
100100
fi
101101

102-
# Format: segment_name background_color foreground_color [non_default_separator] [separator_background_color] [separator_foreground_color] [spacing_disable] [separator_disable]
102+
# Format: segment_name [background_color|default_bg_color] [foreground_color|default_fg_color] [non_default_separator|default_separator] [separator_background_color|no_sep_bg_color]
103+
# [separator_foreground_color|no_sep_fg_color] [spacing_disable|no_spacing_disable] [separator_disable|no_separator_disable]
103104
#
104105
# * background_color and foreground_color. Color formatting (see `man tmux` for complete list):
105106
# * Named colors, e.g. black, red, green, yellow, blue, magenta, cyan, white
106107
# * Hexadecimal RGB string e.g. #ffffff
108+
# * 'default_fg_color|default_bg_color' for the default theme bg and fg color
107109
# * 'default' for the default tmux color.
108110
# * 'terminal' for the terminal's default background/foreground color
109111
# * The numbers 0-255 for the 256-color palette. Run `tmux-powerline/color-palette.sh` to see the colors.
110112
# * non_default_separator - specify an alternative character for this segment's separator
113+
# * 'default_separator' for the theme default separator
111114
# * separator_background_color - specify a unique background color for the separator
115+
# * 'no_sep_bg_color' for using the default coloring for the separator
112116
# * separator_foreground_color - specify a unique foreground color for the separator
117+
# * 'no_sep_fg_color' for using the default coloring for the separator
113118
# * spacing_disable - remove space on left, right or both sides of the segment:
119+
# * "no_spacing_disable" - don't disable spacing (default)
114120
# * "left_disable" - disable space on the left
115121
# * "right_disable" - disable space on the right
116122
# * "both_disable" - disable spaces on both sides
117-
# * - any other character/string produces no change to default behavior (eg "none", "X", etc.)
118123
#
119124
# * separator_disable - disables drawing a separator on this segment, very useful for segments
120125
# with dynamic background colours (eg tmux_mem_cpu_load):
126+
# * "no_separator_disable" - don't disable the separator (default)
121127
# * "separator_disable" - disables the separator
122-
# * - any other character/string produces no change to default behavior
123128
#
124129
# Example segment with separator disabled and right space character disabled:
125-
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 33 0 right_disable separator_disable"
130+
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 0 0 right_disable separator_disable"
126131
#
127-
# Note that although redundant the non_default_separator, separator_background_color and
132+
# Example segment with spacing characters disabled on both sides but not touching the default coloring:
133+
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} no_sep_bg_color no_sep_fg_color both_disable"
134+
#
135+
# Example segment with changing the foreground color of the default separator:
136+
# "hostname 33 0 default_separator no_sep_bg_color 120"
137+
#
138+
## Note that although redundant the non_default_separator, separator_background_color and
128139
# separator_foreground_color options must still be specified so that appropriate index
129-
# of options to support the spacing_disable and separator_disable features can be used
140+
# of options to support the spacing_disable and separator_disable features can be used.
141+
# The default_* and no_* can be used to keep the default behaviour.
130142

131143
# shellcheck disable=SC1143,SC2128
132144
if [ -z "$TMUX_POWERLINE_LEFT_STATUS_SEGMENTS" ]; then

themes/default.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,48 @@ if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_FORMAT" ]; then
5656
)
5757
fi
5858

59-
# Format: segment_name background_color foreground_color [non_default_separator] [separator_background_color] [separator_foreground_color] [spacing_disable] [separator_disable]
59+
# Format: segment_name [background_color|default_bg_color] [foreground_color|default_fg_color] [non_default_separator|default_separator] [separator_background_color|no_sep_bg_color]
60+
# [separator_foreground_color|no_sep_fg_color] [spacing_disable|no_spacing_disable] [separator_disable|no_separator_disable]
6061
#
6162
# * background_color and foreground_color. Color formatting (see `man tmux` for complete list):
6263
# * Named colors, e.g. black, red, green, yellow, blue, magenta, cyan, white
6364
# * Hexadecimal RGB string e.g. #ffffff
65+
# * 'default_fg_color|default_bg_color' for the default theme bg and fg color
6466
# * 'default' for the default tmux color.
6567
# * 'terminal' for the terminal's default background/foreground color
6668
# * The numbers 0-255 for the 256-color palette. Run `tmux-powerline/color-palette.sh` to see the colors.
6769
# * non_default_separator - specify an alternative character for this segment's separator
70+
# * 'default_separator' for the theme default separator
6871
# * separator_background_color - specify a unique background color for the separator
72+
# * 'no_sep_bg_color' for using the default coloring for the separator
6973
# * separator_foreground_color - specify a unique foreground color for the separator
74+
# * 'no_sep_fg_color' for using the default coloring for the separator
7075
# * spacing_disable - remove space on left, right or both sides of the segment:
76+
# * "no_spacing_disable" - don't disable spacing (default)
7177
# * "left_disable" - disable space on the left
7278
# * "right_disable" - disable space on the right
7379
# * "both_disable" - disable spaces on both sides
7480
# * - any other character/string produces no change to default behavior (eg "none", "X", etc.)
7581
#
7682
# * separator_disable - disables drawing a separator on this segment, very useful for segments
7783
# with dynamic background colours (eg tmux_mem_cpu_load):
84+
# * "no_separator_disable" - don't disable the separator (default)
7885
# * "separator_disable" - disables the separator
7986
# * - any other character/string produces no change to default behavior
8087
#
8188
# Example segment with separator disabled and right space character disabled:
82-
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 33 0 right_disable separator_disable"
89+
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} 0 0 right_disable separator_disable"
8390
#
84-
# Note that although redundant the non_default_separator, separator_background_color and
91+
# Example segment with spacing characters disabled on both sides but not touching the default coloring:
92+
# "hostname 33 0 {TMUX_POWERLINE_SEPARATOR_RIGHT_BOLD} no_sep_bg_color no_sep_fg_color both_disable"
93+
#
94+
# Example segment with changing the foreground color of the default separator:
95+
# "hostname 33 0 default_separator no_sep_bg_color 120"
96+
#
97+
## Note that although redundant the non_default_separator, separator_background_color and
8598
# separator_foreground_color options must still be specified so that appropriate index
8699
# of options to support the spacing_disable and separator_disable features can be used
100+
# The default_* and no_* can be used to keep the default behaviour.
87101

88102
# shellcheck disable=SC1143,SC2128
89103
if [ -z "$TMUX_POWERLINE_LEFT_STATUS_SEGMENTS" ]; then

0 commit comments

Comments
 (0)