Skip to content

Commit 99d6b2a

Browse files
committed
theme/powerline-multiline: cleanup
1 parent b140234 commit 99d6b2a

File tree

3 files changed

+51
-54
lines changed

3 files changed

+51
-54
lines changed

clean_files.txt

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ themes/easy
151151
themes/essential
152152
themes/modern
153153
themes/powerline
154+
themes/powerline-multiline
154155
themes/pure
155156
themes/purity
156157

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

+28-33
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
source "${BASH_IT?}/themes/powerline/powerline.base.bash"
55

66
function __powerline_last_status_prompt {
7-
[[ "$1" -ne 0 ]] && echo "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}"
7+
[[ "$1" -ne 0 ]] && echo "$(set_color "${LAST_STATUS_THEME_PROMPT_COLOR?}" -) ${1} ${normal?}"
88
}
99

1010
function __powerline_right_segment {
@@ -17,92 +17,87 @@ function __powerline_right_segment {
1717
if [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -ne 0 ]]; then
1818
pad_before_segment=""
1919
fi
20-
RIGHT_PROMPT+="$(set_color ${params[1]} -)${POWERLINE_RIGHT_END}${normal}"
20+
RIGHT_PROMPT+="$(set_color "${params[1]:-}" -)${POWERLINE_RIGHT_END?}${normal?}"
2121
((padding += 1))
2222
else
23-
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -ne 0 ]]; then
23+
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-}" -ne 0 ]]; then
2424
pad_before_segment=""
2525
fi
2626
# Since the previous segment wasn't the last segment, add padding, if needed
2727
#
28-
if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -eq 0 ]]; then
29-
RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}"
28+
if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR:-0}" -eq 0 ]]; then
29+
RIGHT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal}"
3030
((padding += 1))
3131
fi
32-
if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]}" ]]; then
33-
RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR})${POWERLINE_RIGHT_SEPARATOR_SOFT}${normal}"
32+
if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]:-}" ]]; then
33+
RIGHT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_RIGHT_SEPARATOR_SOFT?}${normal?}"
3434
else
35-
RIGHT_PROMPT+="$(set_color ${params[1]} ${LAST_SEGMENT_COLOR})${POWERLINE_RIGHT_SEPARATOR}${normal}"
35+
RIGHT_PROMPT+="$(set_color "${params[1]:-}" "${LAST_SEGMENT_COLOR?}")${POWERLINE_RIGHT_SEPARATOR?}${normal?}"
3636
fi
3737
((padding += 1))
3838
fi
3939

40-
RIGHT_PROMPT+="$(set_color - ${params[1]})${pad_before_segment}${params[0]}${normal}"
40+
RIGHT_PROMPT+="$(set_color - "${params[1]:-}")${pad_before_segment}${params[0]}${normal?}"
4141

4242
((padding += ${#pad_before_segment}))
4343
((padding += ${#params[0]}))
4444

4545
((RIGHT_PROMPT_LENGTH += padding))
46-
LAST_SEGMENT_COLOR="${params[1]}"
46+
LAST_SEGMENT_COLOR="${params[1]:-}"
4747
((SEGMENTS_AT_RIGHT += 1))
4848
}
4949

5050
function __powerline_right_first_segment_padding {
51-
RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}"
51+
RIGHT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal?}"
5252
((RIGHT_PROMPT_LENGTH += 1))
5353
}
5454

5555
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

6868
## left prompt ##
69-
for segment in $POWERLINE_LEFT_PROMPT; do
70-
local info="$(__powerline_${segment}_prompt)"
69+
for segment in ${POWERLINE_LEFT_PROMPT?}; do
70+
info="$("__powerline_${segment}_prompt")"
7171
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
7272
done
7373

74-
if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then
74+
if [[ -n "${LEFT_PROMPT:-}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-0}" -eq 0 ]]; then
7575
__powerline_left_last_segment_padding
7676
fi
7777

78-
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${POWERLINE_LEFT_END}${normal}"
78+
[[ -n "${LEFT_PROMPT:-}" ]] && LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR?}" -)${POWERLINE_LEFT_END?}${normal?}"
7979

8080
## right prompt ##
8181
if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then
8282
# LEFT_PROMPT+="${move_cursor_rightmost}"
8383
for segment in $POWERLINE_RIGHT_PROMPT; do
84-
local info="$(__powerline_${segment}_prompt)"
84+
info="$("__powerline_${segment}_prompt")"
8585
[[ -n "${info}" ]] && __powerline_right_segment "${info}"
8686
done
8787

88-
if [[ -n "${RIGHT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -eq 0 ]]; then
88+
if [[ -n "${RIGHT_PROMPT:-}" ]] && [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-0}" -eq 0 ]]; then
8989
__powerline_right_first_segment_padding
9090
fi
9191

92-
RIGHT_PAD=$(printf "%.s " $(seq 1 $RIGHT_PROMPT_LENGTH))
92+
RIGHT_PAD=$(printf "%.s " $(seq 1 "${RIGHT_PROMPT_LENGTH}"))
9393
LEFT_PROMPT+="${RIGHT_PAD}${move_cursor_rightmost}"
9494
LEFT_PROMPT+="\033[$((${#RIGHT_PAD} - 1))D"
9595
fi
9696

97-
local prompt="${PROMPT_CHAR}"
98-
if [[ "${POWERLINE_COMPACT_PROMPT}" -eq 0 ]]; then
97+
prompt="${PROMPT_CHAR?}"
98+
if [[ "${POWERLINE_COMPACT_PROMPT:-0}" -eq 0 ]]; then
9999
prompt+=" "
100100
fi
101101

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
102+
PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt "${last_status}")${prompt}"
108103
}

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)