Skip to content

Commit 1df68c1

Browse files
authored
Merge pull request #2051 from gaelicWizard/theme/powerline-multiline
2 parents 863f8e2 + 46d79be commit 1df68c1

File tree

3 files changed

+87
-71
lines changed

3 files changed

+87
-71
lines changed

clean_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ themes/oh-my-posh
7171
themes/p4helpers.theme.bash
7272
themes/pete
7373
themes/powerline
74+
themes/powerline-multiline
7475
themes/pure
7576
themes/purity
7677
themes/rjorgenson
Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,121 @@
1-
. "$BASH_IT/themes/powerline/powerline.base.bash"
2-
3-
function __powerline_last_status_prompt {
4-
[[ "$1" -ne 0 ]] && echo "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}"
5-
}
6-
7-
function __powerline_right_segment {
8-
local OLD_IFS="${IFS}"
9-
IFS="|"
10-
local params=($1)
11-
IFS="${OLD_IFS}"
12-
local padding=0
1+
# shellcheck shell=bash
2+
# shellcheck disable=SC2034 # Expected behavior for themes.
3+
# shellcheck source-path=SCRIPTDIR/../powerline
4+
source "${BASH_IT?}/themes/powerline/powerline.base.bash"
5+
6+
function __powerline_right_segment() {
7+
local -a params
8+
IFS="|" read -ra params <<< "${1}"
139
local pad_before_segment=" "
10+
local padding=0
1411

1512
if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then
16-
if [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -ne 0 ]]; then
13+
if [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -ne 0 ]]; then
1714
pad_before_segment=""
1815
fi
19-
RIGHT_PROMPT+="$(set_color ${params[1]} -)${POWERLINE_RIGHT_END}${normal}"
16+
RIGHT_PROMPT+="$(set_color "${params[1]:-}" -)${POWERLINE_RIGHT_LAST_SEGMENT_END_CHAR:-}${normal?}"
2017
((padding += 1))
2118
else
22-
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -ne 0 ]]; then
19+
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-}" -ne 0 ]]; then
2320
pad_before_segment=""
2421
fi
2522
# Since the previous segment wasn't the last segment, add padding, if needed
2623
#
27-
if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -eq 0 ]]; then
28-
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}"
2926
((padding += 1))
3027
fi
31-
if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]}" ]]; then
32-
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?}"
3330
else
34-
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?}"
3532
fi
3633
((padding += 1))
3734
fi
3835

39-
RIGHT_PROMPT+="$(set_color "${POWERLINE_PROMPT_FOREGROUND_COLOR}" ${params[1]})${pad_before_segment}${params[0]}${normal}"
36+
RIGHT_PROMPT+="$(set_color - "${params[1]:-}")${pad_before_segment}${params[0]}${normal?}"
4037

4138
((padding += ${#pad_before_segment}))
4239
((padding += ${#params[0]}))
4340

4441
((RIGHT_PROMPT_LENGTH += padding))
45-
LAST_SEGMENT_COLOR="${params[1]}"
42+
LAST_SEGMENT_COLOR="${params[1]:-}"
4643
((SEGMENTS_AT_RIGHT += 1))
4744
}
4845

49-
function __powerline_right_first_segment_padding {
50-
RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}"
46+
function __powerline_right_first_segment_padding() {
47+
RIGHT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal?}"
5148
((RIGHT_PROMPT_LENGTH += 1))
5249
}
5350

54-
function __powerline_prompt_command {
51+
function __powerline_last_status_prompt() {
52+
if [[ "${1?}" -ne 0 ]]; then
53+
printf '%b %s %b' "$(set_color "${LAST_STATUS_THEME_PROMPT_COLOR-"52"}" -)" "${1}" "${normal?}"
54+
fi
55+
}
56+
57+
function __powerline_prompt_command() {
5558
local last_status="$?" ## always the first
56-
local move_cursor_rightmost='\033[500C'
59+
local beginning_of_line='\[\e[G\]'
60+
local move_cursor_rightmost='\e[500C'
61+
local info prompt_color segment prompt
5762

58-
LEFT_PROMPT=""
59-
RIGHT_PROMPT=""
60-
RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING}
61-
SEGMENTS_AT_LEFT=0
62-
SEGMENTS_AT_RIGHT=0
63-
LAST_SEGMENT_COLOR=""
63+
local LEFT_PROMPT=""
64+
local RIGHT_PROMPT=""
65+
local RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING:-2}
66+
local SEGMENTS_AT_LEFT=0
67+
local SEGMENTS_AT_RIGHT=0
68+
local LAST_SEGMENT_COLOR=""
6469

6570
_save-and-reload-history "${HISTORY_AUTOSAVE:-0}"
6671

72+
if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO:-}" ]]; then
73+
LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR?}" "${PROMPT_DISTRO_LOGO_COLORBG?}")${PROMPT_DISTRO_LOGO?}$(set_color - -)"
74+
fi
75+
6776
## left prompt ##
68-
for segment in $POWERLINE_LEFT_PROMPT; do
69-
local info="$(__powerline_${segment}_prompt)"
70-
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
77+
# shellcheck disable=SC2068 # intended behavior
78+
for segment in ${POWERLINE_PROMPT[@]-"user_info" "scm" "python_venv" "ruby" "node" "cwd"}; do
79+
info="$("__powerline_${segment}_prompt")"
80+
if [[ -n "${info}" ]]; then
81+
__powerline_left_segment "${info}"
82+
fi
7183
done
7284

73-
if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then
85+
if [[ -n "${LEFT_PROMPT:-}" && "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then
7486
__powerline_left_last_segment_padding
7587
fi
7688

77-
[[ -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
7896

7997
## right prompt ##
80-
if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then
98+
if [[ -n "${POWERLINE_RIGHT_PROMPT[*]:-}" ]]; then
8199
# LEFT_PROMPT+="${move_cursor_rightmost}"
82-
for segment in $POWERLINE_RIGHT_PROMPT; do
83-
local info="$(__powerline_${segment}_prompt)"
100+
# shellcheck disable=SC2068 # intended behavior
101+
for segment in ${POWERLINE_RIGHT_PROMPT[@]}; do
102+
info="$("__powerline_${segment}_prompt")"
84103
[[ -n "${info}" ]] && __powerline_right_segment "${info}"
85104
done
86105

87-
if [[ -n "${RIGHT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -eq 0 ]]; then
106+
if [[ -n "${RIGHT_PROMPT:-}" && "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then
88107
__powerline_right_first_segment_padding
89108
fi
90109

91-
RIGHT_PAD=$(printf "%.s " $(seq 1 $RIGHT_PROMPT_LENGTH))
110+
RIGHT_PAD=$(printf "%.s " $(seq 1 "${RIGHT_PROMPT_LENGTH}"))
92111
LEFT_PROMPT+="${RIGHT_PAD}${move_cursor_rightmost}"
93112
LEFT_PROMPT+="\033[$((${#RIGHT_PAD} - 1))D"
94113
fi
95114

96-
local prompt="${PROMPT_CHAR}"
97-
if [[ "${POWERLINE_COMPACT_PROMPT}" -eq 0 ]]; then
115+
prompt="${prompt_color}${PROMPT_CHAR-${POWERLINE_PROMPT_CHAR-\\$}}${normal?}"
116+
if [[ "${POWERLINE_COMPACT_PROMPT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then
98117
prompt+=" "
99118
fi
100119

101-
PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt ${last_status})${prompt}"
102-
103-
## cleanup ##
104-
unset LAST_SEGMENT_COLOR \
105-
LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \
106-
SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT
120+
PS1="${beginning_of_line}${normal?}${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt "${last_status}")${prompt}"
107121
}

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

Lines changed: 22 additions & 21 deletions
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_LAST_SEGMENT_END_CHAR:=""}"
12+
: "${POWERLINE_RIGHT_LAST_SEGMENT_END_CHAR:=""}"
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
POWERLINE_PROMPT_FOREGROUND_COLOR=${POWERLINE_PROMPT_FOREGROUND_COLOR:=-}
2223

@@ -71,12 +72,12 @@ LAST_STATUS_THEME_PROMPT_COLOR=${POWERLINE_LAST_STATUS_COLOR:=196}
7172

7273
CLOCK_THEME_PROMPT_COLOR=${POWERLINE_CLOCK_COLOR:=240}
7374

74-
BATTERY_AC_CHAR=${BATTERY_AC_CHAR:=""}
75+
: "${BATTERY_AC_CHAR:=""}"
7576
BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=${POWERLINE_BATTERY_GOOD_COLOR:=70}
7677
BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=${POWERLINE_BATTERY_LOW_COLOR:=208}
7778
BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=${POWERLINE_BATTERY_CRITICAL_COLOR:=160}
7879

79-
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"}
80+
: "${THEME_CLOCK_FORMAT:="%H:%M:%S"}"
8081

8182
IN_VIM_THEME_PROMPT_COLOR=${POWERLINE_IN_VIM_COLOR:=245}
8283
IN_VIM_THEME_PROMPT_TEXT=${POWERLINE_IN_VIM_TEXT:="vim"}
@@ -103,7 +104,7 @@ GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "}
103104

104105
COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129}
105106

106-
POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"}
107-
POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"}
107+
: "${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"}"
108+
: "${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"}"
108109

109110
safe_append_prompt_command __powerline_prompt_command

0 commit comments

Comments
 (0)