theme/powerline-multiline: cleanup
parent
fd0e7f4b0c
commit
5956ea2f8c
|
|
@ -10,10 +10,10 @@ function __powerline_right_segment() {
|
||||||
local padding=0
|
local padding=0
|
||||||
|
|
||||||
if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then
|
if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then
|
||||||
if [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -ne 0 ]]; then
|
if [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -ne 0 ]]; then
|
||||||
pad_before_segment=""
|
pad_before_segment=""
|
||||||
fi
|
fi
|
||||||
RIGHT_PROMPT+="$(set_color "${params[1]:-}" -)${POWERLINE_RIGHT_END?}${normal?}"
|
RIGHT_PROMPT+="$(set_color "${params[1]:-}" -)${POWERLINE_RIGHT_LAST_SEGMENT_END_CHAR:-}${normal?}"
|
||||||
((padding += 1))
|
((padding += 1))
|
||||||
else
|
else
|
||||||
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-}" -ne 0 ]]; then
|
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-}" -ne 0 ]]; then
|
||||||
|
|
@ -26,9 +26,9 @@ function __powerline_right_segment() {
|
||||||
((padding += 1))
|
((padding += 1))
|
||||||
fi
|
fi
|
||||||
if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]:-}" ]]; then
|
if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]:-}" ]]; then
|
||||||
RIGHT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_RIGHT_SEPARATOR_SOFT?}${normal?}"
|
RIGHT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_RIGHT_SEPARATOR_SOFT- }${normal?}"
|
||||||
else
|
else
|
||||||
RIGHT_PROMPT+="$(set_color "${params[1]:-}" "${LAST_SEGMENT_COLOR?}")${POWERLINE_RIGHT_SEPARATOR?}${normal?}"
|
RIGHT_PROMPT+="$(set_color "${params[1]:-}" "${LAST_SEGMENT_COLOR?}")${POWERLINE_RIGHT_SEPARATOR- }${normal?}"
|
||||||
fi
|
fi
|
||||||
((padding += 1))
|
((padding += 1))
|
||||||
fi
|
fi
|
||||||
|
|
@ -49,16 +49,20 @@ function __powerline_right_first_segment_padding() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_last_status_prompt() {
|
function __powerline_last_status_prompt() {
|
||||||
[[ "$1" -ne 0 ]] && echo "$(set_color "${LAST_STATUS_THEME_PROMPT_COLOR?}" -) ${1} ${normal?}"
|
if [[ "${1?}" -ne 0 ]]; then
|
||||||
|
printf '%b %s %b' "$(set_color "${LAST_STATUS_THEME_PROMPT_COLOR-"52"}" -)" "${1}" "${normal?}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_prompt_command() {
|
function __powerline_prompt_command() {
|
||||||
local last_status="$?" ## always the first
|
local last_status="$?" ## always the first
|
||||||
local move_cursor_rightmost='\033[500C' info prompt
|
local beginning_of_line='\[\e[G\]'
|
||||||
|
local move_cursor_rightmost='\e[500C'
|
||||||
|
local info prompt_color segment prompt
|
||||||
|
|
||||||
local LEFT_PROMPT=""
|
local LEFT_PROMPT=""
|
||||||
local RIGHT_PROMPT=""
|
local RIGHT_PROMPT=""
|
||||||
local RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING?}
|
local RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING:-2}
|
||||||
local SEGMENTS_AT_LEFT=0
|
local SEGMENTS_AT_LEFT=0
|
||||||
local SEGMENTS_AT_RIGHT=0
|
local SEGMENTS_AT_RIGHT=0
|
||||||
local LAST_SEGMENT_COLOR=""
|
local LAST_SEGMENT_COLOR=""
|
||||||
|
|
@ -70,26 +74,36 @@ function __powerline_prompt_command() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## left prompt ##
|
## left prompt ##
|
||||||
for segment in ${POWERLINE_PROMPT-"user_info scm python_venv ruby node cwd"}; do
|
# shellcheck disable=SC2068 # intended behavior
|
||||||
|
for segment in ${POWERLINE_PROMPT[@]-"user_info" "scm" "python_venv" "ruby" "node" "cwd"}; do
|
||||||
info="$("__powerline_${segment}_prompt")"
|
info="$("__powerline_${segment}_prompt")"
|
||||||
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
|
if [[ -n "${info}" ]]; then
|
||||||
|
__powerline_left_segment "${info}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -n "${LEFT_PROMPT:-}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-0}" -eq 0 ]]; then
|
if [[ -n "${LEFT_PROMPT:-}" && "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then
|
||||||
__powerline_left_last_segment_padding
|
__powerline_left_last_segment_padding
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "${LEFT_PROMPT:-}" ]] && LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR?}" -)${POWERLINE_LEFT_END?}${normal?}"
|
# By default we try to match the prompt to the adjacent segment's background color,
|
||||||
|
# but when part of the prompt exists within that segment, we instead match the foreground color.
|
||||||
|
prompt_color="$(set_color "${LAST_SEGMENT_COLOR?}" -)"
|
||||||
|
if [[ -n "${LEFT_PROMPT:-}" && -n "${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR:-}" ]]; then
|
||||||
|
LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR}"
|
||||||
|
prompt_color="${normal?}"
|
||||||
|
fi
|
||||||
|
|
||||||
## right prompt ##
|
## right prompt ##
|
||||||
if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then
|
if [[ -n "${POWERLINE_RIGHT_PROMPT[*]:-}" ]]; then
|
||||||
# LEFT_PROMPT+="${move_cursor_rightmost}"
|
# LEFT_PROMPT+="${move_cursor_rightmost}"
|
||||||
for segment in $POWERLINE_RIGHT_PROMPT; do
|
# shellcheck disable=SC2068 # intended behavior
|
||||||
|
for segment in ${POWERLINE_RIGHT_PROMPT[@]}; do
|
||||||
info="$("__powerline_${segment}_prompt")"
|
info="$("__powerline_${segment}_prompt")"
|
||||||
[[ -n "${info}" ]] && __powerline_right_segment "${info}"
|
[[ -n "${info}" ]] && __powerline_right_segment "${info}"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -n "${RIGHT_PROMPT:-}" ]] && [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-0}" -eq 0 ]]; then
|
if [[ -n "${RIGHT_PROMPT:-}" && "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then
|
||||||
__powerline_right_first_segment_padding
|
__powerline_right_first_segment_padding
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -98,10 +112,10 @@ function __powerline_prompt_command() {
|
||||||
LEFT_PROMPT+="\033[$((${#RIGHT_PAD} - 1))D"
|
LEFT_PROMPT+="\033[$((${#RIGHT_PAD} - 1))D"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
prompt="${PROMPT_CHAR?}"
|
prompt="${prompt_color}${PROMPT_CHAR-${POWERLINE_PROMPT_CHAR-\\$}}${normal?}"
|
||||||
if [[ "${POWERLINE_COMPACT_PROMPT:-0}" -eq 0 ]]; then
|
if [[ "${POWERLINE_COMPACT_PROMPT:-${POWERLINE_COMPACT:-0}}" -eq 0 ]]; then
|
||||||
prompt+=" "
|
prompt+=" "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt "${last_status}")${prompt}"
|
PS1="${beginning_of_line}${normal?}${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt "${last_status}")${prompt}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:="❯"}
|
||||||
: "${POWERLINE_LEFT_SEPARATOR_SOFT:=""}"
|
: "${POWERLINE_LEFT_SEPARATOR_SOFT:=""}"
|
||||||
: "${POWERLINE_RIGHT_SEPARATOR:=""}"
|
: "${POWERLINE_RIGHT_SEPARATOR:=""}"
|
||||||
: "${POWERLINE_RIGHT_SEPARATOR_SOFT:=""}"
|
: "${POWERLINE_RIGHT_SEPARATOR_SOFT:=""}"
|
||||||
: "${POWERLINE_LEFT_END:=""}"
|
: "${POWERLINE_LEFT_LAST_SEGMENT_END_CHAR:=""}"
|
||||||
: "${POWERLINE_RIGHT_END:=""}"
|
: "${POWERLINE_RIGHT_LAST_SEGMENT_END_CHAR:=""}"
|
||||||
: "${POWERLINE_PADDING:=2}"
|
: "${POWERLINE_PADDING:=2}"
|
||||||
|
|
||||||
: "${POWERLINE_COMPACT:=0}"
|
: "${POWERLINE_COMPACT:=0}"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue