3
3
# shellcheck source-path=SCRIPTDIR/../powerline
4
4
source " ${BASH_IT?} /themes/powerline/powerline.base.bash"
5
5
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() {
11
7
local -a params
12
8
IFS=" |" read -ra params <<< " ${1}"
13
9
local pad_before_segment=" "
@@ -17,92 +13,95 @@ function __powerline_right_segment {
17
13
if [[ " ${POWERLINE_COMPACT_AFTER_LAST_SEGMENT} " -ne 0 ]]; then
18
14
pad_before_segment=" "
19
15
fi
20
- RIGHT_PROMPT+=" $( set_color ${params[1]} -) ${POWERLINE_RIGHT_END}${normal} "
16
+ RIGHT_PROMPT+=" $( set_color " ${params[1]:- } " -) ${POWERLINE_RIGHT_END? }${normal? } "
21
17
(( padding += 1 ))
22
18
else
23
- if [[ " ${POWERLINE_COMPACT_BEFORE_SEPARATOR} " -ne 0 ]]; then
19
+ if [[ " ${POWERLINE_COMPACT_BEFORE_SEPARATOR:- } " -ne 0 ]]; then
24
20
pad_before_segment=" "
25
21
fi
26
22
# Since the previous segment wasn't the last segment, add padding, if needed
27
23
#
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} "
30
26
(( padding += 1 ))
31
27
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? } "
34
30
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? } "
36
32
fi
37
33
(( padding += 1 ))
38
34
fi
39
35
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? } "
41
37
42
38
(( padding += ${# pad_before_segment} ))
43
39
(( padding += ${# params[0]} ))
44
40
45
41
(( RIGHT_PROMPT_LENGTH += padding))
46
- LAST_SEGMENT_COLOR=" ${params[1]} "
42
+ LAST_SEGMENT_COLOR=" ${params[1]:- } "
47
43
(( SEGMENTS_AT_RIGHT += 1 ))
48
44
}
49
45
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? } "
52
48
(( RIGHT_PROMPT_LENGTH += 1 ))
53
49
}
54
50
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() {
56
56
local last_status=" $? " # # always the first
57
- local move_cursor_rightmost=' \033[500C'
57
+ local move_cursor_rightmost=' \033[500C' info prompt
58
58
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=" "
65
65
66
66
_save-and-reload-history " ${HISTORY_AUTOSAVE:- 0} "
67
67
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
+
68
72
# # 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" ) "
71
75
[[ -n " ${info} " ]] && __powerline_left_segment " ${info} "
72
76
done
73
77
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
75
79
__powerline_left_last_segment_padding
76
80
fi
77
81
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? } "
79
83
80
84
# # right prompt ##
81
85
if [[ -n " ${POWERLINE_RIGHT_PROMPT} " ]]; then
82
86
# LEFT_PROMPT+="${move_cursor_rightmost}"
83
87
for segment in $POWERLINE_RIGHT_PROMPT ; do
84
- local info=" $( __powerline_${segment} _prompt) "
88
+ info=" $( " __powerline_${segment} _prompt" ) "
85
89
[[ -n " ${info} " ]] && __powerline_right_segment " ${info} "
86
90
done
87
91
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
89
93
__powerline_right_first_segment_padding
90
94
fi
91
95
92
- RIGHT_PAD=$( printf " %.s " $( seq 1 $ RIGHT_PROMPT_LENGTH) )
96
+ RIGHT_PAD=$( printf " %.s " $( seq 1 " ${ RIGHT_PROMPT_LENGTH} " ) )
93
97
LEFT_PROMPT+=" ${RIGHT_PAD}${move_cursor_rightmost} "
94
98
LEFT_PROMPT+=" \033[$(( ${# RIGHT_PAD} - 1 )) D"
95
99
fi
96
100
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
99
103
prompt+=" "
100
104
fi
101
105
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} "
108
107
}
0 commit comments