33# shellcheck source-path=SCRIPTDIR/../powerline
44source " ${BASH_IT?} /themes/powerline/powerline.base.bash"
55
6- function __powerline_last_status_prompt {
7- [[ " $1 " -ne 0 ]] && echo " $( set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal} "
8- }
9-
10- function __powerline_right_segment {
6+ function __powerline_right_segment() {
117 local -a params
128 IFS=" |" read -ra params <<< " ${1}"
139 local pad_before_segment=" "
@@ -17,92 +13,95 @@ function __powerline_right_segment {
1713 if [[ " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT} " -ne 0 ]]; then
1814 pad_before_segment=" "
1915 fi
20- RIGHT_PROMPT+=" $( set_color ${params[1]} -) ${POWERLINE_RIGHT_END}${normal} "
16+ RIGHT_PROMPT+=" $( set_color " ${params[1]:- } " -) ${POWERLINE_RIGHT_END? }${normal? } "
2117 (( padding += 1 ))
2218 else
23- if [[ " ${POWERLINE_COMPACT_BEFORE_SEPARATOR} " -ne 0 ]]; then
19+ if [[ " ${POWERLINE_COMPACT_BEFORE_SEPARATOR:- } " -ne 0 ]]; then
2420 pad_before_segment=" "
2521 fi
2622 # Since the previous segment wasn't the last segment, add padding, if needed
2723 #
28- if [[ " ${POWERLINE_COMPACT_AFTER_SEPARATOR} " -eq 0 ]]; then
29- RIGHT_PROMPT+=" $( set_color - ${LAST_SEGMENT_COLOR} ) ${normal} "
24+ if [[ " ${POWERLINE_COMPACT_AFTER_SEPARATOR:- 0 } " -eq 0 ]]; then
25+ RIGHT_PROMPT+=" $( set_color - " ${LAST_SEGMENT_COLOR?} " ) ${normal} "
3026 (( padding += 1 ))
3127 fi
32- if [[ " ${LAST_SEGMENT_COLOR} " -eq " ${params[1]} " ]]; then
33- RIGHT_PROMPT+=" $( set_color - ${LAST_SEGMENT_COLOR} ) ${POWERLINE_RIGHT_SEPARATOR_SOFT}${normal} "
28+ if [[ " ${LAST_SEGMENT_COLOR} " -eq " ${params[1]:- } " ]]; then
29+ RIGHT_PROMPT+=" $( set_color - " ${LAST_SEGMENT_COLOR?} " ) ${POWERLINE_RIGHT_SEPARATOR_SOFT? }${normal? } "
3430 else
35- 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? } "
3632 fi
3733 (( padding += 1 ))
3834 fi
3935
40- RIGHT_PROMPT+=" $( set_color - ${params[1]} ) ${pad_before_segment}${params[0]}${normal} "
36+ RIGHT_PROMPT+=" $( set_color - " ${params[1]:- } " ) ${pad_before_segment}${params[0]}${normal? } "
4137
4238 (( padding += ${# pad_before_segment} ))
4339 (( padding += ${# params[0]} ))
4440
4541 (( RIGHT_PROMPT_LENGTH += padding))
46- LAST_SEGMENT_COLOR=" ${params[1]} "
42+ LAST_SEGMENT_COLOR=" ${params[1]:- } "
4743 (( SEGMENTS_AT_RIGHT += 1 ))
4844}
4945
50- function __powerline_right_first_segment_padding {
51- RIGHT_PROMPT+=" $( set_color - ${LAST_SEGMENT_COLOR} ) ${normal} "
46+ function __powerline_right_first_segment_padding() {
47+ RIGHT_PROMPT+=" $( set_color - " ${LAST_SEGMENT_COLOR?} " ) ${normal? } "
5248 (( RIGHT_PROMPT_LENGTH += 1 ))
5349}
5450
55- function __powerline_prompt_command {
51+ function __powerline_last_status_prompt() {
52+ [[ " $1 " -ne 0 ]] && echo " $( set_color " ${LAST_STATUS_THEME_PROMPT_COLOR?} " -) ${1} ${normal?} "
53+ }
54+
55+ function __powerline_prompt_command() {
5656 local last_status=" $? " # # always the first
57- local move_cursor_rightmost=' \033[500C'
57+ local move_cursor_rightmost=' \033[500C' info prompt
5858
59- LEFT_PROMPT=" "
60- RIGHT_PROMPT=" "
61- RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING}
62- SEGMENTS_AT_LEFT=0
63- SEGMENTS_AT_RIGHT=0
64- LAST_SEGMENT_COLOR=" "
59+ local LEFT_PROMPT=" "
60+ local RIGHT_PROMPT=" "
61+ local RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING? }
62+ local SEGMENTS_AT_LEFT=0
63+ local SEGMENTS_AT_RIGHT=0
64+ local LAST_SEGMENT_COLOR=" "
6565
6666 _save-and-reload-history " ${HISTORY_AUTOSAVE:- 0} "
6767
68+ if [[ -n " ${POWERLINE_PROMPT_DISTRO_LOGO:- } " ]]; then
69+ LEFT_PROMPT+=" $( set_color " ${PROMPT_DISTRO_LOGO_COLOR?} " " ${PROMPT_DISTRO_LOGO_COLORBG?} " ) ${PROMPT_DISTRO_LOGO?} $( set_color - -) "
70+ fi
71+
6872 # # left prompt ##
69- for segment in $POWERLINE_LEFT_PROMPT ; do
70- local info=" $( __powerline_${segment} _prompt) "
73+ for segment in ${POWERLINE_PROMPT- " user_info scm python_venv ruby node cwd " } ; do
74+ info=" $( " __powerline_${segment} _prompt" ) "
7175 [[ -n " ${info} " ]] && __powerline_left_segment " ${info} "
7276 done
7377
74- if [[ -n " ${LEFT_PROMPT} " ]] && [[ " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT} " -eq 0 ]]; then
78+ if [[ -n " ${LEFT_PROMPT:- } " ]] && [[ " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:- 0 } " -eq 0 ]]; then
7579 __powerline_left_last_segment_padding
7680 fi
7781
78- [[ -n " ${LEFT_PROMPT} " ]] && LEFT_PROMPT+=" $( set_color ${LAST_SEGMENT_COLOR} -) ${POWERLINE_LEFT_END}${normal} "
82+ [[ -n " ${LEFT_PROMPT:- } " ]] && LEFT_PROMPT+=" $( set_color " ${LAST_SEGMENT_COLOR?} " -) ${POWERLINE_LEFT_END? }${normal? } "
7983
8084 # # right prompt ##
8185 if [[ -n " ${POWERLINE_RIGHT_PROMPT} " ]]; then
8286 # LEFT_PROMPT+="${move_cursor_rightmost}"
8387 for segment in $POWERLINE_RIGHT_PROMPT ; do
84- local info=" $( __powerline_${segment} _prompt) "
88+ info=" $( " __powerline_${segment} _prompt" ) "
8589 [[ -n " ${info} " ]] && __powerline_right_segment " ${info} "
8690 done
8791
88- if [[ -n " ${RIGHT_PROMPT} " ]] && [[ " ${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT} " -eq 0 ]]; then
92+ if [[ -n " ${RIGHT_PROMPT:- } " ]] && [[ " ${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:- 0 } " -eq 0 ]]; then
8993 __powerline_right_first_segment_padding
9094 fi
9195
92- RIGHT_PAD=$( printf " %.s " $( seq 1 $ RIGHT_PROMPT_LENGTH) )
96+ RIGHT_PAD=$( printf " %.s " $( seq 1 " ${ RIGHT_PROMPT_LENGTH} " ) )
9397 LEFT_PROMPT+=" ${RIGHT_PAD}${move_cursor_rightmost} "
9498 LEFT_PROMPT+=" \033[$(( ${# RIGHT_PAD} - 1 )) D"
9599 fi
96100
97- local prompt=" ${PROMPT_CHAR} "
98- if [[ " ${POWERLINE_COMPACT_PROMPT} " -eq 0 ]]; then
101+ prompt=" ${PROMPT_CHAR? } "
102+ if [[ " ${POWERLINE_COMPACT_PROMPT:- 0 } " -eq 0 ]]; then
99103 prompt+=" "
100104 fi
101105
102- PS1=" ${LEFT_PROMPT}${RIGHT_PROMPT} \n$( __powerline_last_status_prompt ${last_status} ) ${prompt} "
103-
104- # # cleanup ##
105- unset LAST_SEGMENT_COLOR \
106- LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \
107- SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT
106+ PS1=" ${LEFT_PROMPT}${RIGHT_PROMPT} \n$( __powerline_last_status_prompt " ${last_status} " ) ${prompt} "
108107}
0 commit comments