@@ -10,10 +10,10 @@ function __powerline_right_segment() {
1010 local padding=0
1111
1212 if [[ " ${SEGMENTS_AT_RIGHT} " -eq 0 ]]; then
13- if [[ " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT} " -ne 0 ]]; then
13+ if [[ " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:- ${POWERLINE_COMPACT :- 0} } " -ne 0 ]]; then
1414 pad_before_segment=" "
1515 fi
16- RIGHT_PROMPT+=" $( set_color " ${params[1]:- } " -) ${POWERLINE_RIGHT_END? }${normal?} "
16+ RIGHT_PROMPT+=" $( set_color " ${params[1]:- } " -) ${POWERLINE_RIGHT_LAST_SEGMENT_END_CHAR :- }${normal?} "
1717 (( padding += 1 ))
1818 else
1919 if [[ " ${POWERLINE_COMPACT_BEFORE_SEPARATOR:- } " -ne 0 ]]; then
@@ -26,9 +26,9 @@ function __powerline_right_segment() {
2626 (( padding += 1 ))
2727 fi
2828 if [[ " ${LAST_SEGMENT_COLOR} " -eq " ${params[1]:- } " ]]; then
29- RIGHT_PROMPT+=" $( set_color - " ${LAST_SEGMENT_COLOR?} " ) ${POWERLINE_RIGHT_SEPARATOR_SOFT? }${normal?} "
29+ RIGHT_PROMPT+=" $( set_color - " ${LAST_SEGMENT_COLOR?} " ) ${POWERLINE_RIGHT_SEPARATOR_SOFT- }${normal?} "
3030 else
31- RIGHT_PROMPT+=" $( set_color " ${params[1]:- } " " ${LAST_SEGMENT_COLOR?} " ) ${POWERLINE_RIGHT_SEPARATOR? }${normal?} "
31+ RIGHT_PROMPT+=" $( set_color " ${params[1]:- } " " ${LAST_SEGMENT_COLOR?} " ) ${POWERLINE_RIGHT_SEPARATOR- }${normal?} "
3232 fi
3333 (( padding += 1 ))
3434 fi
@@ -49,16 +49,20 @@ function __powerline_right_first_segment_padding() {
4949}
5050
5151function __powerline_last_status_prompt() {
52- [[ " $1 " -ne 0 ]] && echo " $( set_color " ${LAST_STATUS_THEME_PROMPT_COLOR?} " -) ${1} ${normal?} "
52+ if [[ " ${1?} " -ne 0 ]]; then
53+ printf ' %b %s %b' " $( set_color " ${LAST_STATUS_THEME_PROMPT_COLOR-" 52" } " -) " " ${1} " " ${normal?} "
54+ fi
5355}
5456
5557function __powerline_prompt_command() {
5658 local last_status=" $? " # # always the first
57- local move_cursor_rightmost=' \033[500C' info prompt
59+ local beginning_of_line=' \[\e[G\]'
60+ local move_cursor_rightmost=' \e[500C'
61+ local info prompt_color segment prompt
5862
5963 local LEFT_PROMPT=" "
6064 local RIGHT_PROMPT=" "
61- local RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING? }
65+ local RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING:- 2 }
6266 local SEGMENTS_AT_LEFT=0
6367 local SEGMENTS_AT_RIGHT=0
6468 local LAST_SEGMENT_COLOR=" "
@@ -70,26 +74,36 @@ function __powerline_prompt_command() {
7074 fi
7175
7276 # # left prompt ##
73- for segment in ${POWERLINE_PROMPT-" user_info scm python_venv ruby node cwd" } ; do
77+ # shellcheck disable=SC2068 # intended behavior
78+ for segment in ${POWERLINE_PROMPT[@]-" user_info" " scm" " python_venv" " ruby" " node" " cwd" } ; do
7479 info=" $( " __powerline_${segment} _prompt" ) "
75- [[ -n " ${info} " ]] && __powerline_left_segment " ${info} "
80+ if [[ -n " ${info} " ]]; then
81+ __powerline_left_segment " ${info} "
82+ fi
7683 done
7784
78- if [[ -n " ${LEFT_PROMPT:- } " ]] && [[ " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:- 0 } " -eq 0 ]]; then
85+ if [[ -n " ${LEFT_PROMPT:- } " && " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:- ${POWERLINE_COMPACT :- 0} } " -eq 0 ]]; then
7986 __powerline_left_last_segment_padding
8087 fi
8188
82- [[ -n " ${LEFT_PROMPT:- } " ]] && LEFT_PROMPT+=" $( set_color " ${LAST_SEGMENT_COLOR?} " -) ${POWERLINE_LEFT_END?}${normal?} "
89+ # By default we try to match the prompt to the adjacent segment's background color,
90+ # but when part of the prompt exists within that segment, we instead match the foreground color.
91+ prompt_color=" $( set_color " ${LAST_SEGMENT_COLOR?} " -) "
92+ if [[ -n " ${LEFT_PROMPT:- } " && -n " ${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR:- } " ]]; then
93+ LEFT_PROMPT+=" $( set_color - " ${LAST_SEGMENT_COLOR?} " ) ${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR} "
94+ prompt_color=" ${normal?} "
95+ fi
8396
8497 # # right prompt ##
85- if [[ -n " ${POWERLINE_RIGHT_PROMPT} " ]]; then
98+ if [[ -n " ${POWERLINE_RIGHT_PROMPT[*] :- } " ]]; then
8699 # LEFT_PROMPT+="${move_cursor_rightmost}"
87- for segment in $POWERLINE_RIGHT_PROMPT ; do
100+ # shellcheck disable=SC2068 # intended behavior
101+ for segment in ${POWERLINE_RIGHT_PROMPT[@]} ; do
88102 info=" $( " __powerline_${segment} _prompt" ) "
89103 [[ -n " ${info} " ]] && __powerline_right_segment " ${info} "
90104 done
91105
92- if [[ -n " ${RIGHT_PROMPT:- } " ]] && [[ " ${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:- 0 } " -eq 0 ]]; then
106+ if [[ -n " ${RIGHT_PROMPT:- } " && " ${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:- ${POWERLINE_COMPACT :- 0} } " -eq 0 ]]; then
93107 __powerline_right_first_segment_padding
94108 fi
95109
@@ -98,10 +112,10 @@ function __powerline_prompt_command() {
98112 LEFT_PROMPT+=" \033[$(( ${# RIGHT_PAD} - 1 )) D"
99113 fi
100114
101- prompt=" ${PROMPT_CHAR?} "
102- if [[ " ${POWERLINE_COMPACT_PROMPT:- 0 } " -eq 0 ]]; then
115+ prompt=" ${prompt_color}${ PROMPT_CHAR- ${POWERLINE_PROMPT_CHAR- \\ $} }${normal ?} "
116+ if [[ " ${POWERLINE_COMPACT_PROMPT:- ${POWERLINE_COMPACT :- 0} } " -eq 0 ]]; then
103117 prompt+=" "
104118 fi
105119
106- PS1=" ${LEFT_PROMPT}${RIGHT_PROMPT} \n$( __powerline_last_status_prompt " ${last_status} " ) ${prompt} "
120+ PS1=" ${beginning_of_line}${normal?}${ LEFT_PROMPT}${RIGHT_PROMPT} \n$( __powerline_last_status_prompt " ${last_status} " ) ${prompt} "
107121}
0 commit comments