Skip to content

Commit 7e87e76

Browse files
committed
theme/powerline-multiline: cleanup
1 parent cda381d commit 7e87e76

File tree

3 files changed

+61
-60
lines changed

3 files changed

+61
-60
lines changed

clean_files.txt

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ themes/modern
161161
themes/norbu
162162
themes/pete
163163
themes/powerline
164+
themes/powerline-multiline
164165
themes/pure
165166
themes/purity
166167

themes/powerline-multiline/powerline-multiline.base.bash

+38-39
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
# shellcheck source-path=SCRIPTDIR/../powerline
44
source "${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
}

themes/powerline-multiline/powerline-multiline.theme.bash

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
#!/usr/bin/env bash
2-
3-
. "$BASH_IT/themes/powerline-multiline/powerline-multiline.base.bash"
1+
# shellcheck shell=bash
2+
# shellcheck disable=SC2034 # Expected behavior for themes.
3+
# shellcheck source-path=SCRIPTDIR/../powerline-multiline
4+
source "${BASH_IT?}/themes/powerline-multiline/powerline-multiline.base.bash"
45

56
PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""}
6-
POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""}
7-
POWERLINE_LEFT_SEPARATOR_SOFT=${POWERLINE_LEFT_SEPARATOR_SOFT:=""}
8-
POWERLINE_RIGHT_SEPARATOR=${POWERLINE_RIGHT_SEPARATOR:=""}
9-
POWERLINE_RIGHT_SEPARATOR_SOFT=${POWERLINE_RIGHT_SEPARATOR_SOFT:=""}
10-
POWERLINE_LEFT_END=${POWERLINE_LEFT_END:=""}
11-
POWERLINE_RIGHT_END=${POWERLINE_RIGHT_END:=""}
12-
POWERLINE_PADDING=${POWERLINE_PADDING:=2}
13-
14-
POWERLINE_COMPACT=${POWERLINE_COMPACT:=0}
15-
POWERLINE_COMPACT_BEFORE_SEPARATOR=${POWERLINE_COMPACT_BEFORE_SEPARATOR:=${POWERLINE_COMPACT}}
16-
POWERLINE_COMPACT_AFTER_SEPARATOR=${POWERLINE_COMPACT_AFTER_SEPARATOR:=${POWERLINE_COMPACT}}
17-
POWERLINE_COMPACT_BEFOR_FIRST_SEGMENT=${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:=${POWERLINE_COMPACT}}
18-
POWERLINE_COMPACT_AFTER_LAST_SEGMENT=${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${POWERLINE_COMPACT}}
19-
POWERLINE_COMPACT_PROMPT=${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}}
7+
: "${POWERLINE_LEFT_SEPARATOR:=""}"
8+
: "${POWERLINE_LEFT_SEPARATOR_SOFT:=""}"
9+
: "${POWERLINE_RIGHT_SEPARATOR:=""}"
10+
: "${POWERLINE_RIGHT_SEPARATOR_SOFT:=""}"
11+
: "${POWERLINE_LEFT_END:=""}"
12+
: "${POWERLINE_RIGHT_END:=""}"
13+
: "${POWERLINE_PADDING:=2}"
14+
15+
: "${POWERLINE_COMPACT:=0}"
16+
: "${POWERLINE_COMPACT_BEFORE_SEPARATOR:=${POWERLINE_COMPACT}}"
17+
: "${POWERLINE_COMPACT_AFTER_SEPARATOR:=${POWERLINE_COMPACT}}"
18+
: "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:=${POWERLINE_COMPACT}}"
19+
: "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:=${POWERLINE_COMPACT}}"
20+
: "${POWERLINE_COMPACT_PROMPT:=${POWERLINE_COMPACT}}"
2021

2122
USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=""}
2223
USER_INFO_THEME_PROMPT_COLOR=${POWERLINE_USER_INFO_COLOR:=32}
@@ -67,12 +68,12 @@ LAST_STATUS_THEME_PROMPT_COLOR=${POWERLINE_LAST_STATUS_COLOR:=196}
6768

6869
CLOCK_THEME_PROMPT_COLOR=${POWERLINE_CLOCK_COLOR:=240}
6970

70-
BATTERY_AC_CHAR=${BATTERY_AC_CHAR:=""}
71+
: "${BATTERY_AC_CHAR:=""}"
7172
BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=${POWERLINE_BATTERY_GOOD_COLOR:=70}
7273
BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=${POWERLINE_BATTERY_LOW_COLOR:=208}
7374
BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=${POWERLINE_BATTERY_CRITICAL_COLOR:=160}
7475

75-
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"}
76+
: "${THEME_CLOCK_FORMAT:="%H:%M:%S"}"
7677

7778
IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245}
7879
IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"}
@@ -99,7 +100,7 @@ GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "}
99100

100101
COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129}
101102

102-
POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"}
103-
POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"}
103+
: "${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"}"
104+
: "${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"}"
104105

105106
safe_append_prompt_command __powerline_prompt_command

0 commit comments

Comments
 (0)