diff options
-rwxr-xr-x | internal/p10k.zsh | 753 |
1 files changed, 456 insertions, 297 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh index cbdc5fe2..a10e8a86 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -75,45 +75,119 @@ _p9k_cache_get() { [[ -n $v ]] && _P9K_CACHE_VAL=("${(@0)${v[1,-2]}}") } -typeset -gA _p9k_icon_cache=() +typeset -ga _P9K_LEFT_JOIN=(1) +typeset -ga _P9K_RIGHT_JOIN=(1) -# Sets _P9K_RETVAL to the icon whose name is supplied via $1. -_p9k_get_icon() { - _P9K_RETVAL=$_p9k_icon_cache[$1] +# _p9k_param prompt_foo_BAR BACKGROUND red +_p9k_param() { + local key="_p9k_param ${(pj:\0:)*}" + _P9K_RETVAL=$_P9K_CACHE[key] if [[ -n $_P9K_RETVAL ]]; then _P9K_RETVAL[-1,-1]='' else - if [[ $1 == $'\1'* ]]; then - _P9K_RETVAL=${1[2,-1]} + if [[ $1 == (#b)prompt_([a-z0-9_]#)(*) ]]; then + local var=POWERLEVEL9K_${(U)match[1]}$match[2]_$2 + if (( $+parameters[$var] )); then + _P9K_RETVAL=${(P)var} + else + var=POWERLEVEL9K_${(U)match[1]%_}_$2 + if (( $+parameters[$var] )); then + _P9K_RETVAL=${(P)var} + else + var=POWERLEVEL9K_$2 + if (( $+parameters[$var] )); then + _P9K_RETVAL=${(P)var} + else + _P9K_RETVAL=$3 + fi + fi + fi else - local x=POWERLEVEL9K_$1 - (( $+parameters[$x] )) && x=${(P)x} || x=$icons[$1] - _P9K_RETVAL=${(g::)x} - [[ $_P9K_RETVAL != $'\b'? ]] || _P9K_RETVAL="%{$_P9K_RETVAL%}" # penance for past sins + local var=POWERLEVEL9K_$2 + if (( $+parameters[$var] )); then + _P9K_RETVAL=${(P)var} + else + _P9K_RETVAL=$3 + fi fi - _p9k_icon_cache[$1]=${_P9K_RETVAL}. + _P9K_CACHE[$key]=${_P9K_RETVAL}. fi } -typeset -ga _P9K_LEFT_JOIN=(1) -typeset -ga _P9K_RIGHT_JOIN=(1) +# _p9k_get_icon prompt_foo_BAR BAZ_ICON quix +_p9k_get_icon() { + local key="_p9k_param ${(pj:\0:)*}" + _P9K_RETVAL=$_P9K_CACHE[key] + if [[ -n $_P9K_RETVAL ]]; then + _P9K_RETVAL[-1,-1]='' + else + if [[ $2 == $'\1'* ]]; then + _P9K_RETVAL=${2[2,-1]} + else + _p9k_param "$@" ${icons[$2]-$'\1'$3} + if [[ $_P9K_RETVAL == $'\1'* ]]; then + _P9K_RETVAL=${_P9K_RETVAL[2,-1]} + else + _P9K_RETVAL=${(g::)_P9K_RETVAL} + [[ $_P9K_RETVAL != $'\b'? ]] || _P9K_RETVAL="%{$_P9K_RETVAL%}" # penance for past sins + fi + fi + _P9K_CACHE[$key]=${_P9K_RETVAL}. + fi +} _p9k_translate_color() { - if [[ $1 == <-> ]]; then # decimal color code: 255 + if [[ $1 == <-> ]]; then # decimal color code: 255 _P9K_RETVAL=$1 - elif [[ $1 == '#'* ]]; then # hexademical color code: #ffffff + elif [[ $1 == '#'[[:xdigit:]]## ]]; then # hexademical color code: #ffffff _P9K_RETVAL=$1 - else # named color: red + else # named color: red # Strip prifixes if there are any. _P9K_RETVAL=$__P9K_COLORS[${${${1#bg-}#fg-}#br}] fi } -# Resolves a color to its numerical value, or an empty string. Communicates the result back -# by setting _P9K_RETVAL. +# _p9k_param prompt_foo_BAR BACKGROUND red _p9k_color() { - local user_var=POWERLEVEL9K_${(U)${2}#prompt_}_${3} - _p9k_translate_color ${${(P)user_var}:-${1}} + local key="_p9k_color ${(pj:\0:)*}" + _P9K_RETVAL=$_P9K_CACHE[key] + if [[ -n $_P9K_RETVAL ]]; then + _P9K_RETVAL[-1,-1]='' + else + _p9k_param "$@" + _p9k_translate_color $_P9K_RETVAL + _P9K_CACHE[$key]=${_P9K_RETVAL}. + fi +} + +# _p9k_vcs_color CLEAN REMOTE_BRANCH +_p9k_vcs_style() { + local key="_p9k_vcs_color ${(pj:\0:)*}" + _P9K_RETVAL=$_P9K_CACHE[key] + if [[ -n $_P9K_RETVAL ]]; then + _P9K_RETVAL[-1,-1]='' + else + local style=%b # TODO: support bold + _p9k_color prompt_vcs_$1 BACKGROUND "${vcs_states[$1]}" + _p9k_background $_P9K_RETVAL + style+=$_P9K_RETVAL + + local var=POWERLEVEL9K_VCS_${1}_${2}FORMAT_FOREGROUND + if (( $+parameters[$var] )); then + _P9K_RETVAL=${(P)var} + else + var=POWERLEVEL9K_VCS_${2}FORMAT_FOREGROUND + if (( $+parameters[$var] )); then + _P9K_RETVAL=${(P)var} + else + _p9k_color prompt_vcs_$1 FOREGROUND "$DEFAULT_COLOR" + fi + fi + + _p9k_foreground $_P9K_RETVAL + _P9K_RETVAL=$style$_P9K_RETVAL + _P9K_CACHE[$key]=${_P9K_RETVAL}. + fi } _p9k_background() { @@ -128,192 +202,368 @@ _p9k_escape_rcurly() { _P9K_RETVAL=${${1//\\/\\\\}//\}/\\\}} } -# Begin a left prompt segment. -# -# * $1: Name of the function that was originally invoked. -# Necessary, to make the dynamic color-overwrite mechanism work. -# * $2: The array index of the current segment. -# * $3: Background color. -# * $4: Foreground color. -# * $5: An identifying icon (must be a key of the icons array). -# * $6: 1 to to perform parameter expansion and process substitution. -# * $7: If not empty but becomes empty after parameter expansion and process substitution, -# the segment isn't rendered. -# * $8+: The segment content +_p9k_escape() { + [[ $1 == *["~!#\$^&*()\\\"'<>?{}[]"]* ]] && _P9K_RETVAL="\${(Q)\${:-${(qqq)${(q)1}}}}" || _P9K_RETVAL=$1 +} + +# * $1: Name of the function that was originally invoked. +# Necessary, to make the dynamic color-overwrite mechanism work. +# * $2: The array index of the current segment. +# * $3: Background color. +# * $4: Foreground color. +# * $5: An identifying icon. +# * $6: 1 to to perform parameter expansion and process substitution. +# * $7: If not empty but becomes empty after parameter expansion and process substitution, +# the segment isn't rendered. +# * $8: Content. set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " left_prompt_segment() { if ! _p9k_cache_get "$0" "$1" "$2" "$3" "$4" "$5"; then - _p9k_color $3 $1 BACKGROUND + _p9k_color $1 BACKGROUND $3 local bg_color=$_P9K_RETVAL _p9k_background $bg_color local bg=$_P9K_RETVAL - _p9k_color $4 $1 FOREGROUND + _p9k_color $1 FOREGROUND $4 local fg_color=$_P9K_RETVAL _p9k_foreground $fg_color local fg=$_P9K_RETVAL - _p9k_get_icon LEFT_SUBSEGMENT_SEPARATOR - local subsep=$_P9K_RETVAL - - _p9k_escape_rcurly $POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS - local space=$_P9K_RETVAL + _p9k_get_icon $1 LEFT_SEGMENT_SEPARATOR + local sep=$_P9K_RETVAL + _p9k_escape $_P9K_RETVAL + local sep_=$_P9K_RETVAL - local line_start=$POWERLEVEL9K_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL - [[ -n $line_start ]] && line_start="%F{$bg_color}$line_start%b%k%f" + _p9k_get_icon $1 LEFT_SUBSEGMENT_SEPARATOR + _p9k_escape $_P9K_RETVAL + local subsep_=$_P9K_RETVAL - local icon - local -i has_icon + local icon_ if [[ -n $5 ]]; then - _p9k_get_icon $5 - if [[ -n $_P9K_RETVAL ]]; then - local glyph=$_P9K_RETVAL - _p9k_color $fg_color $1 VISUAL_IDENTIFIER_COLOR - _p9k_foreground $_P9K_RETVAL - _p9k_escape_rcurly %b$bg$_P9K_RETVAL$glyph - icon=$_P9K_RETVAL - has_icon=1 - fi + _p9k_get_icon $1 $5 + _p9k_escape $_P9K_RETVAL + icon_=$_P9K_RETVAL fi + _p9k_get_icon $1 LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL + local start_sep=$_P9K_RETVAL + [[ -n $start_sep ]] && start_sep="%b%k%F{$bg_color}$start_sep" + + _p9k_get_icon $1 LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL $sep + _p9k_escape $_P9K_RETVAL + local end_sep_=$_P9K_RETVAL + + local style=%b$bg$fg + _p9k_escape_rcurly $style + local style_=$_P9K_RETVAL + + _p9k_get_icon $1 WHITESPACE_BETWEEN_LEFT_SEGMENTS + local space=$_P9K_RETVAL + + _p9k_get_icon $1 LEFT_LEFT_WHITESPACE $space + local left_space=$_P9K_RETVAL + [[ $left_space == *%* ]] && left_space+=$style + + _p9k_get_icon $1 LEFT_RIGHT_WHITESPACE $space + _p9k_escape $_P9K_RETVAL + local right_space_=$_P9K_RETVAL + [[ $right_space_ == *%* ]] && right_space_+=$style_ + + local s='<_P9K_S>' ss='<_P9K_SS>' + # Segment separator logic: # # if [[ $_P9K_BG == NONE ]]; then # 1 # elif (( joined )); then # 2 - # elif [[ $bg_color == $_P9K_BG ]]; then + # elif [[ $bg_color == (${_P9K_BG}|${_P9K_BG:-0}) ]]; then # 3 # else # 4 # fi local t=$#_P9K_T - _P9K_T+=$line_start$bg$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS # 1 - _P9K_T+=$bg # 2 + _P9K_T+=$start_sep$style$left_space # 1 + _P9K_T+=$style # 2 if [[ -z $fg_color ]]; then _p9k_foreground $DEFAULT_COLOR - _P9K_T+=$bg$_P9K_RETVAL$subsep$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS # 3 + _P9K_T+=%b$bg$_P9K_RETVAL$ss$style$left_space # 3 else - _P9K_T+=$bg$fg$subsep$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS # 3 + _P9K_T+=%b$bg$fg$ss$style$left_space # 3 fi - _p9k_get_icon LEFT_SEGMENT_SEPARATOR - _P9K_T+=$bg$_P9K_RETVAL$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS # 4 + _P9K_T+=%b$bg$s$style$left_space # 4 - local pre - pre+="\${_P9K_N::=}\${_P9K_F::=}" - pre+="\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}" # 1 - pre+="\${_P9K_N:=\${\${\$((_P9K_I>=$_P9K_LEFT_JOIN[$2])):#0}:+$((t+2))}}" # 2 - pre+="\${_P9K_N:=\${\${\$((!\${#\${:-0\$_P9K_BG}:#0$bg_color})):#0}:+$((t+3))}}" # 3 - pre+="\${_P9K_N:=\${\${_P9K_F::=%F{\$_P9K_BG\}}+$((t+4))}}}+}" # 4 + local join="_P9K_I>=$_P9K_LEFT_JOIN[$2]" + _p9k_param $1 SELF_JOINED false + [[ $_P9K_RETVAL == false ]] && join+="&&_P9K_I<$2" - _p9k_escape_rcurly %b$bg$fg - local style=$_P9K_RETVAL - local state=${(U)${1}#prompt_} + local p= + p+="\${_P9K_N::=}" + p+="\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}" # 1 + p+="\${_P9K_N:=\${\${\$(($join)):#0}:+$((t+2))}}" # 2 + p+="\${_P9K_N:=\${\${(M)\${:-x$bg_color}:#x(\$_P9K_BG|\${_P9K_BG:-0})}:+$((t+3))}}" # 3 + p+="\${_P9K_N:=$((t+4))}" # 4 - _p9k_get_icon ${state}_PREFIX - _p9k_escape_rcurly $_P9K_RETVAL - pre+="%b\${_P9K_F}\${_P9K_T[\$_P9K_N]}$_P9K_RETVAL$icon" + p+="\${_P9K_I::=$2}\${_P9K_BG::=$bg_color}" - _p9k_get_icon ${state}_SUFFIX - _p9k_escape_rcurly $_P9K_RETVAL - local post="\${_P9K_C}$style$_P9K_RETVAL$style$space\${\${_P9K_I::=$2}+}\${\${_P9K_BG::=$bg_color}+}}" + _p9k_param $1 VISUAL_IDENTIFIER_EXPANSION '${P9K_VISUAL_IDENTIFIER}' + local icon_exp=$_P9K_RETVAL + + _p9k_param $1 CONTENT_EXPANSION '${P9K_CONTENT}' + local content_exp=$_P9K_RETVAL - local tr=POWERLEVEL9K_${state}_CONTENT_TRANSFORMER - (( $+parameters[$tr] )) && tr=${(P)tr} || tr='${P9K_CONTENT}' - _p9k_cache_set "$has_icon" "$style" "$tr" "$pre" "$post" + if [[ $icon_exp == '${P9K_VISUAL_IDENTIFIER}' && $content_exp == '${P9K_CONTENT}' ]]; then + p+="\${_P9K_V::=$icon_" + [[ $icon_ == *%* ]] && p+=$style_ + p+="}" + else + p+="\${P9K_VISUAL_IDENTIFIER::=$icon}\${_P9K_V::=$icon_exp$style_}" + fi + + p+="\${_P9K_C::=$content_exp}" + p+='${_P9K_E::=${${(%):-$_P9K_C%1(l.1.0)}[-1]}${${(%):-$_P9K_V%1(l.1.0)}[-1]}}' + + p+='}+}' + + p+='${${_P9K_E:#00}:+' + + _p9k_param $1 PREFIX '' + _P9K_RETVAL=${(g::)_P9K_RETVAL} + _p9k_escape $_P9K_RETVAL + p+="\${\${_P9K_T[\$_P9K_N]/$ss/\$_P9K_SS}/$s/\$_P9K_S}$_P9K_RETVAL" + [[ $_P9K_RETVAL == *%* ]] && local -i need_style=1 || local -i need_style=0 + + _p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color + _p9k_foreground $_P9K_RETVAL + _p9k_escape_rcurly %b$bg$_P9K_RETVAL + [[ $_P9K_RETVAL != $style_ || $need_style == 1 ]] && p+=$_P9K_RETVAL + p+="\$_P9K_V$style_" + + _p9k_get_icon $1 LEFT_MIDDLE_WHITESPACE $space + if [[ -n $_P9K_RETVAL ]]; then + _p9k_escape $_P9K_RETVAL + [[ _P9K_RETVAL == *%* ]] && _P9K_RETVAL+=$style_ + p+="\${\${(M)_P9K_E:#11}:+$_P9K_RETVAL}" + fi + + p+="\${_P9K_C}$style_" + + _p9k_param $1 SUFFIX '' + _P9K_RETVAL=${(g::)_P9K_RETVAL} + _p9k_escape $_P9K_RETVAL + p+=$_P9K_RETVAL + [[ $_P9K_RETVAL == *%* && -n $right_space_ ]] && p+=$style_ + p+=$right_space_ + + p+="\${\${:-\${_P9K_S::=%F{$bg_color\}$sep_}\${_P9K_SS::=$subsep_}\${_P9K_SSS::=%F{$bg_color\}$end_sep_}}+}" + + p+='}' + + _p9k_cache_set "$p" fi - (( $6 )) && local content=$8 || local content="\${(Q)\${:-${(qqq)${(q)8}}}}" - _P9K_PROMPT+="\${\${:-${7:-1}}:+\${\${:-\${_P9K_C::=${_P9K_CACHE_VAL[2]}\${\${P9K_CONTENT::=$content}+}${_P9K_CACHE_VAL[3]}}${_P9K_CACHE_VAL[4]}" - (( _P9K_CACHE_VAL[1] )) && _P9K_PROMPT+='${${(%):-$_P9K_C%1(l. .x)}[-1]%x}' - _P9K_PROMPT+=${_P9K_CACHE_VAL[5]} + (( $6 )) && _P9K_RETVAL=$8 || _p9k_escape $8 + if [[ -z $7 ]]; then + _P9K_PROMPT+="\${\${:-\${P9K_CONTENT::=$_P9K_RETVAL}$_P9K_CACHE_VAL[1]" + else + _P9K_PROMPT+="\${\${:-$7}:+\${\${:-\${P9K_CONTENT::=$_P9K_RETVAL}$_P9K_CACHE_VAL[1]}" + fi } # The same as left_prompt_segment above but for the right prompt. set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " right_prompt_segment() { if ! _p9k_cache_get "$0" "$1" "$2" "$3" "$4" "$5"; then - _p9k_color $3 $1 BACKGROUND + _p9k_color $1 BACKGROUND $3 local bg_color=$_P9K_RETVAL _p9k_background $bg_color local bg=$_P9K_RETVAL + _p9k_escape_rcurly $_P9K_RETVAL + local bg_=$_P9K_RETVAL - _p9k_color $4 $1 FOREGROUND + _p9k_color $1 FOREGROUND $4 local fg_color=$_P9K_RETVAL _p9k_foreground $fg_color local fg=$_P9K_RETVAL - _p9k_get_icon RIGHT_SUBSEGMENT_SEPARATOR + _p9k_get_icon $1 RIGHT_SEGMENT_SEPARATOR + local sep=$_P9K_RETVAL + _p9k_escape $_P9K_RETVAL + local sep_=$_P9K_RETVAL + + _p9k_get_icon $1 RIGHT_SUBSEGMENT_SEPARATOR local subsep=$_P9K_RETVAL - local icon_style icon - local -i has_icon + local icon_ if [[ -n $5 ]]; then - _p9k_get_icon $5 - if [[ -n $_P9K_RETVAL ]]; then - _p9k_escape_rcurly $_P9K_RETVAL - icon=$_P9K_RETVAL - _p9k_color $fg_color $1 VISUAL_IDENTIFIER_COLOR - _p9k_foreground $_P9K_RETVAL - _p9k_escape_rcurly %b$bg$_P9K_RETVAL - icon_style=$_P9K_RETVAL - has_icon=1 - fi + _p9k_get_icon $1 $5 + _p9k_escape $_P9K_RETVAL + icon_=$_P9K_RETVAL fi - # Segment separator logic is the same as in left_prompt_segment except that here #4 and #1 are - # identical. + _p9k_get_icon $1 RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL $sep + local start_sep=$_P9K_RETVAL + [[ -n $start_sep ]] && start_sep="%b%k%F{$bg_color}$start_sep" + + _p9k_get_icon $1 RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL + _p9k_escape $_P9K_RETVAL + local end_sep_=$_P9K_RETVAL + + local style=%b$bg$fg + _p9k_escape_rcurly $style + local style_=$_P9K_RETVAL + + _p9k_get_icon $1 WHITESPACE_BETWEEN_RIGHT_SEGMENTS + local space=$_P9K_RETVAL + + _p9k_get_icon $1 RIGHT_LEFT_WHITESPACE $space + local left_space=$_P9K_RETVAL + [[ $left_space == *%* ]] && left_space+=$style + + _p9k_get_icon $1 RIGHT_RIGHT_WHITESPACE $space + _p9k_escape $_P9K_RETVAL + local right_space_=$_P9K_RETVAL + [[ $right_space_ == *%* ]] && right_space_+=$style_ + + local w='<_P9K_W>' s='<_P9K_S>' + + # Segment separator logic: + # + # if [[ $_P9K_BG == NONE ]]; then + # 1 + # elif (( joined )); then + # 2 + # elif [[ $_P9K_BG == (${bg_color}|${bg_color:-0}) ]]; then + # 3 + # else + # 4 + # fi local t=$#_P9K_T - _p9k_get_icon RIGHT_SEGMENT_SEPARATOR - _P9K_T+="%F{$bg_color}$_P9K_RETVAL$bg$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS$fg" # 1 - _P9K_T+=$fg # 2 + _P9K_T+=$start_sep$style$left_space # 1 + _P9K_T+=$w$style # 2 if [[ -z $fg_color ]]; then _p9k_foreground $DEFAULT_COLOR - _P9K_T+=$bg$_P9K_RETVAL$subsep$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS$fg # 3 + _P9K_T+=$w%b$bg$_P9K_RETVAL$subsep$style$left_space # 3 else - _P9K_T+=$bg$fg$subsep$POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS # 3 + _P9K_T+=$w%b$bg$fg$subsep$style$left_space # 3 fi + _P9K_T+=$w%F{$bg_color}$sep$style$left_space # 4 - local pre - pre+="\${_P9K_N::=}" - pre+="\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}" # 1 - pre+="\${_P9K_N:=\${\${\$((_P9K_I>=$_P9K_RIGHT_JOIN[$2])):#0}:+$((t+2))}}" # 2 - pre+="\${_P9K_N:=\${\${\$((!\${#\${:-0\$_P9K_BG}:#0$bg_color})):#0}:+$((t+3))}}" # 3 - pre+="\${_P9K_N:=$((t+1))}}+}" # 4 == 1 - (( _P9K_EMULATE_ZERO_RPROMPT_INDENT )) && pre+=' ' + local join="_P9K_I>=$_P9K_RIGHT_JOIN[$2]" + _p9k_param $1 SELF_JOINED false + [[ $_P9K_RETVAL == false ]] && join+="&&_P9K_I<$2" - local state=${(U)${1}#prompt_} + local p= + p+="\${_P9K_N::=}" + p+="\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}" # 1 + p+="\${_P9K_N:=\${\${\$(($join)):#0}:+$((t+2))}}" # 2 + p+="\${_P9K_N:=\${\${(M)\${:-x\$_P9K_BG}:#x(${(b)bg_color}|${(b)bg_color:-0})}:+$((t+3))}}" # 3 + p+="\${_P9K_N:=$((t+4))}" # 4 - _p9k_escape_rcurly %b$bg$fg - local style=$_P9K_RETVAL + p+="\${_P9K_I::=$2}\${_P9K_BG::=$bg_color}" - _p9k_get_icon ${state}_PREFIX - _p9k_escape_rcurly $_P9K_RETVAL - pre+="\${_P9K_T[\$_P9K_N]}$_P9K_RETVAL$style\${_P9K_C}$icon_style" + _p9k_param $1 VISUAL_IDENTIFIER_EXPANSION '${P9K_VISUAL_IDENTIFIER}' + local icon_exp=$_P9K_RETVAL + + _p9k_param $1 CONTENT_EXPANSION '${P9K_CONTENT}' + local content_exp=$_P9K_RETVAL + + if [[ $icon_exp == '${P9K_VISUAL_IDENTIFIER}' && $content_exp == '${P9K_CONTENT}' ]]; then + p+="\${_P9K_V::=$icon_" + [[ $icon_ == *%* ]] && p+=$style_ + p+="}" + else + p+="\${P9K_VISUAL_IDENTIFIER::=$icon}\${_P9K_V::=$icon_exp$style_}" + fi + + p+="\${_P9K_C::=$content_exp}" + p+='${_P9K_E::=${${(%):-$_P9K_C%1(l.1.0)}[-1]}${${(%):-$_P9K_V%1(l.1.0)}[-1]}}' + + p+='}+}' + + p+='${${_P9K_E:#00}:+' + + _p9k_param $1 PREFIX '' + _P9K_RETVAL=${(g::)_P9K_RETVAL} + _p9k_escape $_P9K_RETVAL + p+="\${_P9K_T[\$_P9K_N]/$w/\$_P9K_W}$_P9K_RETVAL" + [[ $_P9K_RETVAL == *%* ]] && p+=$style_ + + p+="\${_P9K_C}$style_" + + local -i need_style=0 + _p9k_get_icon $1 RIGHT_MIDDLE_WHITESPACE $space + if [[ -n $_P9K_RETVAL ]]; then + _p9k_escape $_P9K_RETVAL + [[ $_P9K_RETVAL == *%* ]] && need_style=1 + p+="\${\${(M)_P9K_E:#11}:+$_P9K_RETVAL}" + fi + + _p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color + _p9k_foreground $_P9K_RETVAL + _p9k_escape_rcurly %b$bg$_P9K_RETVAL + [[ $_P9K_RETVAL != $style_ || $need_style == 1 ]] && p+=$_P9K_RETVAL + p+="\$_P9K_V$style_" + + _p9k_param $1 SUFFIX '' + _P9K_RETVAL=${(g::)_P9K_RETVAL} + _p9k_escape $_P9K_RETVAL + p+=$_P9K_RETVAL + + p+="\${\${_P9K_W::=${right_space_:+$style_}$right_space_%b$bg_}+}" if (( _P9K_EMULATE_ZERO_RPROMPT_INDENT )); then - local space='' + p+="\${\${_P9K_SSS::=$bg_%E}+}" + elif [[ -n $right_space_ || -n $end_sep_ ]]; then + p+="\${\${_P9K_SSS::=$style_$right_space_" + [[ $right_space_ == *%* ]] && p+=$style_ + p+="$end_sep_}+}" else - _p9k_escape_rcurly $POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS - local space=$_P9K_RETVAL + p+='${_P9K_SSS::=}' fi - local tr=POWERLEVEL9K_${state}_CONTENT_TRANSFORMER - (( $+parameters[$tr] )) && tr=${(P)tr} || tr='${P9K_CONTENT}' + p+='}' - _p9k_get_icon ${state}_SUFFIX - _p9k_escape_rcurly $_P9K_RETVAL - local post="$icon$style$_P9K_RETVAL$style$space\${\${_P9K_I::=$2}+}\${\${_P9K_BG::=$bg_color}+}}" + _p9k_cache_set "$p" + fi - _p9k_cache_set "$has_icon" "$style" "$tr" "$pre" "$post" + (( $6 )) && _P9K_RETVAL=$8 || _p9k_escape $8 + if [[ -z $7 ]]; then + _P9K_PROMPT+="\${\${:-\${P9K_CONTENT::=$_P9K_RETVAL}$_P9K_CACHE_VAL[1]" + else + _P9K_PROMPT+="\${\${:-$7}:+\${\${:-\${P9K_CONTENT::=$_P9K_RETVAL}$_P9K_CACHE_VAL[1]}" fi +} - (( $6 )) && local content=$8 || local content="\${(Q)\${:-${(qqq)${(q)8}}}}" - _P9K_PROMPT+="\${\${:-${7:-1}}:+\${\${:-\${_P9K_C::=${_P9K_CACHE_VAL[2]}\${\${P9K_CONTENT::=$content}+}${_P9K_CACHE_VAL[3]}}${_P9K_CACHE_VAL[4]}" - (( _P9K_CACHE_VAL[1] )) && _P9K_PROMPT+='${${(%):-$_P9K_C%1(l. .x)}[-1]%x}' - _P9K_PROMPT+=${_P9K_CACHE_VAL[5]} +function p9k_prompt_segment() { + emulate -L zsh && setopt no_hist_expand extended_glob + local opt state bg fg icon cond text sym=0 expand=0 + while getopts 's:b:f:i:c:t:se' opt; do + case $opt in + s) state=$OPTARG;; + b) bg=$OPTARG;; + f) fg=$OPTARG;; + i) icon=$OPTARG;; + c) cond=${OPTARG:-'${:-}'};; + t) text=$OPTARG;; + s) sym=1;; + e) expand=1;; + +s) sym=0;; + +e) expand=0;; + ?) return 1;; + done) break;; + esac + done + if (( OPTIND <= ARGC )) { + echo "usage: p9k_prompt_segment [{+|-}re] [-s state] [-b bg] [-f fg] [-i icon] [-c cond] [-t text]" >&2 + return 1 + } + (( sym )) || icon=$'\1'$icon + "${_P9K_PROMPT_SIDE}_prompt_segment" "prompt_${_P9K_SEGMENT_NAME}${state:+_${(U)state}}" \ + "${_P9K_SEGMENT_INDEX}" "$bg" "${fg:-$DEFAULT_COLOR}" "$icon" "$expand" "$cond" "$text" + return 0 } function _p9k_python_version() { @@ -379,21 +629,11 @@ typeset -gi _P9K_X _P9K_Y _P9K_M _P9K_RPROMPT_DONE _P9K_IND # Returns 1 if the cursor is at the very end of the screen. function _p9k_left_prompt_end_line() { - _p9k_get_icon LEFT_SEGMENT_SEPARATOR - _p9k_escape_rcurly $_P9K_RETVAL - _P9K_PROMPT+="%k%b" - _P9K_PROMPT+="\${_P9K_N::=}" - _P9K_PROMPT+="\${\${\${_P9K_BG:#NONE}:-\${_P9K_N:=1}}+}" - _P9K_PROMPT+="\${\${_P9K_N:=2}+}" - _P9K_PROMPT+="\${\${_P9K_T[2]::=%F{\$_P9K_BG\}$_P9K_RETVAL}+}" - _P9K_PROMPT+="\${_P9K_T[\$_P9K_N]}" - _P9K_PROMPT+="%f$1%f%k%b" - - if (( ! _P9K_RPROMPT_DONE )); then - _P9K_PROMPT+=$_P9K_ALIGNED_RPROMPT - _P9K_RPROMPT_DONE=1 - return 1 - fi + _P9K_PROMPT+=$_P9K_LEFT_LINE_SUFFIX$1 + (( _P9K_RPROMPT_DONE )) && return 0 + _P9K_PROMPT+=$_P9K_ALIGNED_RPROMPT + _P9K_RPROMPT_DONE=1 + return 1 } ################################################################ @@ -403,9 +643,9 @@ set_default POWERLEVEL9K_RPROMPT_ON_NEWLINE false prompt_newline() { [[ "$1" == "right" ]] && return _p9k_left_prompt_end_line && _P9K_PROMPT+=$'\n' - _P9K_PROMPT+='${${_P9K_BG::=NONE}+}' + _P9K_PROMPT+=$_P9K_LEFT_LINE_PREFIX if [[ $POWERLEVEL9K_PROMPT_ON_NEWLINE == true ]]; then - _p9k_get_icon MULTILINE_NEWLINE_PROMPT_PREFIX + _p9k_get_icon '' MULTILINE_NEWLINE_PROMPT_PREFIX _P9K_PROMPT+=$_P9K_RETVAL fi } @@ -944,10 +1184,10 @@ prompt_dir() { fi local style=%b - _p9k_color blue $state BACKGROUND + _p9k_color $state BACKGROUND blue _p9k_background $_P9K_RETVAL style+=$_P9K_RETVAL - _p9k_color "$DEFAULT_COLOR" $state FOREGROUND + _p9k_color $state FOREGROUND "$DEFAULT_COLOR" _p9k_foreground $_P9K_RETVAL style+=$_P9K_RETVAL @@ -1387,23 +1627,6 @@ prompt_root_indicator() { "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" 'ROOT_ICON' 0 '${${(%):-%#}:#%}' '' } -# This segment is a demo. It can disappear any time. Use prompt_dir instead. -prompt_simple_dir() { - if ! _p9k_cache_get "$0" "$1" "$2" ; then - local p=$_P9K_PROMPT - local key=$_P9K_CACHE_KEY - _P9K_PROMPT='' - $1_prompt_segment $0_HOME $2 blue "$DEFAULT_COLOR" HOME_ICON 0 '${$((!${#${(%):-%~}:#\~})):#0}' "%~" - $1_prompt_segment $0_HOME_SUBFOLDER $2 blue "$DEFAULT_COLOR" HOME_SUB_ICON 0 '${$((!${#${(%):-%~}:#\~?*})):#0}' "%~" - $1_prompt_segment $0_ETC $2 blue "$DEFAULT_COLOR" ETC_ICON 0 '${$((!${#${(%):-%~}:#/etc*})):#0}' "%~" - $1_prompt_segment $0_DEFAULT $2 blue "$DEFAULT_COLOR" FOLDER_ICON 0 '${${${(%):-%~}:#\~*}:#/etc*}' "%~" - _P9K_CACHE_KEY=$key - _p9k_cache_set "$_P9K_PROMPT" - _P9K_PROMPT=$p - fi - _P9K_PROMPT+=${_P9K_CACHE_VAL[1]} -} - ################################################################ # Segment to display Rust version number prompt_rust_version() { @@ -1634,12 +1857,12 @@ prompt_todo() { # VCS segment: shows the state of your repository, if you are in a folder under # version control -# The vcs segment can have 4 different states - defaults to 'clean'. +# The vcs segment can have 4 different states - defaults to 'CLEAN'. typeset -gA vcs_states=( - 'clean' 'green' - 'modified' 'yellow' - 'untracked' 'green' - 'loading' 'grey' + 'CLEAN' '2' + 'MODIFIED' '3' + 'UNTRACKED' '2' + 'LOADING' '8' ) set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND red @@ -1660,21 +1883,6 @@ powerlevel9k_vcs_init() { POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH="$POWERLEVEL9K_CHANGESET_HASH_LENGTH" fi - local component state - for component in COMMIT BRANCH DIRTY TAG REMOTE_BRANCH STAGED UNSTAGED \ - UNTRACKED OUTGOING_CHANGES INCOMING_CHANGES STASH ACTION; do - local var=POWERLEVEL9K_VCS_${component}FORMAT_FOREGROUND - local color=${(P)var} - if [[ -n $color ]]; then - for state in "${(@k)vcs_states}"; do - local var=POWERLEVEL9K_VCS_${(U)state}_${component}FORMAT_FOREGROUND - if [[ -z ${(P)var} ]]; then - typeset -g $var=$color - fi - done - fi - done - autoload -Uz vcs_info VCS_CHANGESET_PREFIX='' @@ -1778,8 +1986,8 @@ function _p9k_vcs_render() { _p9k_vcs_status_restore $_P9K_RETVAL state=LOADING else - if [[ -n $POWERLEVEL9K_VCS_LOADING_TEXT ]] || { _p9k_get_icon VCS_LOADING_ICON; [[ -n $_P9K_RETVAL ]] }; then - $1_prompt_segment prompt_vcs_LOADING $2 "${vcs_states[loading]}" "$DEFAULT_COLOR" VCS_LOADING_ICON 0 '' "$POWERLEVEL9K_VCS_LOADING_TEXT" + if [[ -n $POWERLEVEL9K_VCS_LOADING_TEXT ]] || { _p9k_get_icon prompt_vcs_LOADING VCS_LOADING_ICON; [[ -n $_P9K_RETVAL ]] }; then + $1_prompt_segment prompt_vcs_LOADING $2 "${vcs_states[LOADING]}" "$DEFAULT_COLOR" VCS_LOADING_ICON 0 '' "$POWERLEVEL9K_VCS_LOADING_TEXT" fi return 0 fi @@ -1858,34 +2066,25 @@ function _p9k_vcs_render() { : ${state:=CLEAN} - local style=%b - _p9k_color "${vcs_states[${(L)state}]}" prompt_vcs_$state BACKGROUND - _p9k_background $_P9K_RETVAL - style+=$_P9K_RETVAL - _p9k_color "$DEFAULT_COLOR" prompt_vcs_$state FOREGROUND - _p9k_foreground $_P9K_RETVAL - style+=$_P9K_RETVAL - function _$0_fmt() { - local color=${(P)${:-POWERLEVEL9K_VCS_${state}_${1}FORMAT_FOREGROUND}} - [[ -n $color && $color != <-> ]] && color=$__P9K_COLORS[${${${color#bg-}#fg-}#br}] - content+="${color:+%F{$color\}}$2$style" + _p9k_vcs_style $state $1 + content+="$_P9K_RETVAL$2" } local ws if [[ $POWERLEVEL9K_SHOW_CHANGESET == true || -z $VCS_STATUS_LOCAL_BRANCH ]]; then - _p9k_get_icon VCS_COMMIT_ICON + _p9k_get_icon prompt_vcs_$state VCS_COMMIT_ICON _$0_fmt COMMIT "$_P9K_RETVAL${${VCS_STATUS_COMMIT:0:$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH}:-HEAD}" ws=' ' fi if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then - _p9k_get_icon VCS_BRANCH_ICON + _p9k_get_icon prompt_vcs_$state VCS_BRANCH_ICON _$0_fmt BRANCH "$ws$_P9K_RETVAL${VCS_STATUS_LOCAL_BRANCH//\%/%%}" fi if [[ $POWERLEVEL9K_VCS_HIDE_TAGS == false && -n $VCS_STATUS_TAG ]]; then - _p9k_get_icon VCS_TAG_ICON + _p9k_get_icon prompt_vcs_$state VCS_TAG_ICON _$0_fmt TAG " $_P9K_RETVAL${VCS_STATUS_TAG//\%/%%}" fi @@ -1894,45 +2093,45 @@ function _p9k_vcs_render() { else if [[ -n $VCS_STATUS_REMOTE_BRANCH && $VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then - _p9k_get_icon VCS_REMOTE_BRANCH_ICON + _p9k_get_icon prompt_vcs_$state VCS_REMOTE_BRANCH_ICON _$0_fmt REMOTE_BRANCH " $_P9K_RETVAL${VCS_STATUS_REMOTE_BRANCH//\%/%%}" fi if [[ $VCS_STATUS_HAS_STAGED == 1 || $VCS_STATUS_HAS_UNSTAGED == 1 || $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then - _p9k_get_icon VCS_DIRTY_ICON + _p9k_get_icon prompt_vcs_$state VCS_DIRTY_ICON _$0_fmt DIRTY "$_P9K_RETVAL" if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then - _p9k_get_icon VCS_STAGED_ICON + _p9k_get_icon prompt_vcs_$state VCS_STAGED_ICON (( ${POWERLEVEL9K_VCS_MAX_NUM_STAGED:-$POWERLEVEL9K_VCS_STAGED_MAX_NUM} != 1 )) && _P9K_RETVAL+=$VCS_STATUS_NUM_STAGED _$0_fmt STAGED " $_P9K_RETVAL" fi if [[ $VCS_STATUS_HAS_UNSTAGED == 1 ]]; then - _p9k_get_icon VCS_UNSTAGED_ICON + _p9k_get_icon prompt_vcs_$state VCS_UNSTAGED_ICON (( ${POWERLEVEL9K_VCS_MAX_NUM_UNSTAGED:-$POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM} != 1 )) && _P9K_RETVAL+=$VCS_STATUS_NUM_UNSTAGED _$0_fmt UNSTAGED " $_P9K_RETVAL" fi if [[ $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then - _p9k_get_icon VCS_UNTRACKED_ICON + _p9k_get_icon prompt_vcs_$state VCS_UNTRACKED_ICON (( ${POWERLEVEL9K_VCS_MAX_NUM_UNTRACKED:-$POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM} != 1 )) && _P9K_RETVAL+=$VCS_STATUS_NUM_UNTRACKED _$0_fmt UNTRACKED " $_P9K_RETVAL" fi fi if [[ $VCS_STATUS_COMMITS_BEHIND -gt 0 ]]; then - _p9k_get_icon VCS_INCOMING_CHANGES_ICON + _p9k_get_icon prompt_vcs_$state VCS_INCOMING_CHANGES_ICON (( POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM != 1 )) && _P9K_RETVAL+=$VCS_STATUS_COMMITS_BEHIND _$0_fmt INCOMING_CHANGES " $_P9K_RETVAL" fi if [[ $VCS_STATUS_COMMITS_AHEAD -gt 0 ]]; then - _p9k_get_icon VCS_OUTGOING_CHANGES_ICON + _p9k_get_icon prompt_vcs_$state VCS_OUTGOING_CHANGES_ICON (( POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM != 1 )) && _P9K_RETVAL+=$VCS_STATUS_COMMITS_AHEAD _$0_fmt OUTGOING_CHANGES " $_P9K_RETVAL" fi if [[ $VCS_STATUS_STASHES -gt 0 ]]; then - _p9k_get_icon VCS_STASH_ICON + _p9k_get_icon prompt_vcs_$state VCS_STASH_ICON _$0_fmt STASH " $_P9K_RETVAL$VCS_STATUS_STASHES" fi fi - _p9k_cache_set "prompt_vcs_$state" "$2" "${vcs_states[${(L)state}]}" "$DEFAULT_COLOR" "$icon" 0 '' "$content" + _p9k_cache_set "prompt_vcs_$state" "$2" "${vcs_states[$state]}" "$DEFAULT_COLOR" "$icon" 0 '' "$content" fi $1_prompt_segment "$_P9K_CACHE_VAL[@]" @@ -2038,12 +2237,12 @@ prompt_vcs() { if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then # $vcs_visual_identifier gets set in +vi-vcs-detect-changes in functions/vcs.zsh, # as we have there access to vcs_info internal hooks. - current_state='modified' + current_state='MODIFIED' else if [[ "$VCS_WORKDIR_HALF_DIRTY" == true ]]; then - current_state='untracked' + current_state='UNTRACKED' else - current_state='clean' + current_state='CLEAN' fi fi $1_prompt_segment "${0}_${(U)current_state}" "$2" "${vcs_states[$current_state]}" "$DEFAULT_COLOR" "$vcs_visual_identifier" 0 '' "$vcs_prompt" @@ -2261,49 +2460,23 @@ prompt_java_version() { ################################################################ # Main prompt set_default -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS context dir vcs - -# Returns 1 if the cursor is at the very end of the screen. -build_left_prompt() { - local -i index=1 - local element - for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do - # Remove joined information in direct calls - element=${element%_joined} - - # Check if it is a custom command, otherwise interpet it as - # a prompt. - if [[ $element == custom_* ]]; then - "prompt_custom" "left" "$index" $element[8,-1] - else - (( $+functions[prompt_$element] )) && "prompt_$element" "left" "$index" - fi - - ((++index)) - done - - _p9k_get_icon LEFT_SEGMENT_END_SEPARATOR - _p9k_left_prompt_end_line $_P9K_RETVAL -} - -# Right prompt set_default -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS status root_indicator background_jobs history time -build_right_prompt() { - local -i index=1 - local element - - for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do - # Remove joined information in direct calls - element=${element%_joined} - - # Check if it is a custom command, otherwise interpet it as - # a prompt. - if [[ $element == custom_* ]]; then - "prompt_custom" "right" "$index" $element[8,-1] - else - (( $+functions[prompt_$element] )) && "prompt_$element" "right" "$index" - fi - ((++index)) +typeset -g _P9K_PROMPT_SIDE _P9K_SEGMENT_NAME +typeset -gi _P9K_SEGMENT_INDEX + +_p9k_build_prompt() { + _P9K_SEGMENT_INDEX=1 + _P9K_PROMPT_SIDE=$1 + local list=POWERLEVEL9K_${(U)_P9K_PROMPT_SIDE}_PROMPT_ELEMENTS + for _P9K_SEGMENT_NAME in ${(P)list}; do + _P9K_SEGMENT_NAME=${_P9K_SEGMENT_NAME%_joined} + if [[ $_P9K_SEGMENT_NAME == custom_* ]]; then + prompt_custom $_P9K_PROMPT_SIDE $_P9K_SEGMENT_INDEX $_P9K_SEGMENT_NAME[8,-1] + elif (( $+functions[prompt_$_P9K_SEGMENT_NAME] )); then + prompt_$_P9K_SEGMENT_NAME $_P9K_PROMPT_SIDE $_P9K_SEGMENT_INDEX + fi + ((++_P9K_SEGMENT_INDEX)) done } @@ -2335,7 +2508,7 @@ function _p9k_set_prompt() { _P9K_RPROMPT_DONE=1 else _P9K_PROMPT= - build_right_prompt + _p9k_build_prompt right local right=$_P9K_RIGHT_PREFIX$_P9K_PROMPT$_P9K_RIGHT_SUFFIX if [[ $POWERLEVEL9K_PROMPT_ON_NEWLINE != true || $POWERLEVEL9K_RPROMPT_ON_NEWLINE == true ]]; then RPROMPT=$right @@ -2348,7 +2521,9 @@ function _p9k_set_prompt() { fi _P9K_PROMPT='' - if build_left_prompt; then + _p9k_build_prompt left + _p9k_get_icon '' LEFT_SEGMENT_END_SEPARATOR + if _p9k_left_prompt_end_line $_P9K_RETVAL%b%k%f; then PROMPT+=$_P9K_LEFT_PREFIX$_P9K_PROMPT$_P9K_LEFT_SUFFIX else PROMPT+=$_P9K_LEFT_PREFIX$_P9K_PROMPT${_P9K_LEFT_SUFFIX#$'\n'} @@ -2602,10 +2777,6 @@ _p9k_init_strings() { _p9k_g_expand POWERLEVEL9K_VCS_LOADING_TEXT _p9k_g_expand POWERLEVEL9K_VI_COMMAND_MODE_STRING _p9k_g_expand POWERLEVEL9K_VI_INSERT_MODE_STRING - _p9k_g_expand POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS - _p9k_g_expand POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS - _p9k_g_expand POWERLEVEL9K_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL - _p9k_g_expand POWERLEVEL9K_RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL } _p9k_init() { @@ -2616,7 +2787,7 @@ _p9k_init() { function _$0_set_os() { OS=$1 - _p9k_get_icon $2 + _p9k_get_icon prompt_os_icon $2 OS_ICON=$_P9K_RETVAL } @@ -2695,24 +2866,17 @@ _p9k_init() { fi done - if [[ -n $POWERLEVEL9K_RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL ]]; then - _p9k_escape_rcurly $POWERLEVEL9K_RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL - _P9K_RIGHT_SUFFIX+="\${_P9K_N::=}" - _P9K_RIGHT_SUFFIX+="\${\${\${\${:-x\$_P9K_BG}:#xNONE}:-\${_P9K_N:=3}}+}" - _P9K_RIGHT_SUFFIX+="\${\${_P9K_N:=4}+}" - _P9K_RIGHT_SUFFIX+="\${\${_P9K_T[4]::=%b%k%F{\$_P9K_BG\}$_P9K_RETVAL}+}" - _P9K_RIGHT_SUFFIX+="\${_P9K_T[\$_P9K_N]}" - fi + _P9K_RIGHT_SUFFIX+='$_P9K_SSS' # Bug fixed in: https://github.com/zsh-users/zsh/commit/3eea35d0853bddae13fa6f122669935a01618bf9. # If affects most terminals when RPROMPT is non-empty and ZLE_RPROMPT_INDENT is zero. # We can work around it as long as RPROMPT ends with a space. if [[ ($POWERLEVEL9K_RPROMPT_ON_NEWLINE == true || $POWERLEVEL9K_PROMPT_ON_NEWLINE == false) && $POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS == ' ' && $ZLE_RPROMPT_INDENT == 0 && - -z $POWERLEVEL9K_RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL ]] && ! is-at-least 5.7.2; then + -z $(typeset -m 'POWERLEVEL9K_*(RIGHT_RIGHT_WHITESPACE|RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL)') ]] && + ! is-at-least 5.7.2; then _P9K_EMULATE_ZERO_RPROMPT_INDENT=1 _P9K_LEFT_PREFIX+='${${:-${_P9K_REAL_ZLE_RPROMPT_INDENT:=$ZLE_RPROMPT_INDENT}${ZLE_RPROMPT_INDENT::=1}}+}' - _P9K_RIGHT_SUFFIX+='%E' fi _P9K_ALIGNED_RPROMPT='${${:-${_P9K_X::=0}${_P9K_Y::=1024}${_P9K_CLM::=$COLUMNS}${COLUMNS::=1024}' @@ -2733,7 +2897,7 @@ _p9k_init() { _P9K_ALIGNED_RPROMPT+='%-$_P9K_X(l. .)' done _P9K_ALIGNED_RPROMPT+='%$(((COLUMNS-_P9K_X+2)*(COLUMNS+2>=_P9K_X)))' - _P9K_ALIGNED_RPROMPT+=$'(l.\n. ${_P9K_RPROMPT//)/%)}$_P9K_T[$((5+!_P9K_IND))])' + _P9K_ALIGNED_RPROMPT+=$'(l.\n. ${_P9K_RPROMPT//)/%)}$_P9K_T[$((1+!_P9K_IND))])' _P9K_LEFT_PREFIX+='${${_P9K_IND::=${${ZLE_RPROMPT_INDENT:-1}/#-*/0}}+}' @@ -2742,20 +2906,20 @@ _p9k_init() { fi if [[ $POWERLEVEL9K_SHOW_RULER == true ]]; then - _p9k_get_icon RULER_CHAR + _p9k_get_icon '' RULER_CHAR local ruler_char=$_P9K_RETVAL _p9k_prompt_length $ruler_char if (( _P9K_RETVAL == 1 && $#ruler_char == 1 )); then - _p9k_color "" prompt_ruler BACKGROUND + _p9k_color prompt_ruler BACKGROUND "" _p9k_background $_P9K_RETVAL _P9K_LEFT_PREFIX+=%b$_P9K_RETVAL - _p9k_color "" prompt_ruler FOREGROUND + _p9k_color prompt_ruler FOREGROUND "" _p9k_foreground $_P9K_RETVAL _P9K_LEFT_PREFIX+=$_P9K_RETVAL [[ $ruler_char == '.' ]] && local sep=',' || local sep='.' local ruler_len='${$((COLUMNS-_P9K_IND))/#-*/0}' _P9K_LEFT_PREFIX+="\${(pl$sep$ruler_len$sep$sep${(q)ruler_char}$sep)}%k%f" - _P9K_LEFT_PREFIX+='$_P9K_T[$((5+!_P9K_IND))]' + _P9K_LEFT_PREFIX+='$_P9K_T[$((1+!_P9K_IND))]' else print -P "%F{red}WARNING!%f %BPOWERLEVEL9K_RULER_CHAR%b is not one character long. Ruler won't be rendered." print -P "Either change the value of %BPOWERLEVEL9K_RULER_CHAR%b or set %BPOWERLEVEL9K_SHOW_RULER=false%b to" @@ -2767,33 +2931,28 @@ _p9k_init() { _P9K_LEFT_PREFIX+="%{$(iterm2_prompt_mark)%}" fi - _P9K_LEFT_PREFIX+='${${_P9K_BG::=NONE}+}${${_P9K_I::=0}+}' - _P9K_RIGHT_PREFIX+='${${_P9K_BG::=NONE}+}${${_P9K_I::=0}+}' + _p9k_get_icon '' LEFT_SEGMENT_SEPARATOR + _p9k_get_icon '' LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL $_P9K_RETVAL + _p9k_escape $_P9K_RETVAL + _P9K_LEFT_LINE_PREFIX='${${:-${_P9K_BG::=NONE}${_P9K_I::=0}${_P9K_SSS::=%f'$_P9K_RETVAL'}}+}' + + _P9K_LEFT_LINE_SUFFIX='%b%k$_P9K_SSS%b%k%f' + + _P9K_LEFT_PREFIX+=$_P9K_LEFT_LINE_PREFIX + _P9K_RIGHT_PREFIX+='${${:-${_P9K_BG::=NONE}${_P9K_I::=0}${_P9K_SSS::=}}+}' - # left prompt end _P9K_T=( - "" "" # left prompt end - "" "" # right prompt end $'\n' "" # left prompt overflow ) - if [[ -n $POWERLEVEL9K_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL ]]; then - _P9K_T[1]+="%f$POWERLEVEL9K_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL" - fi - _p9k_get_icon LEFT_SEGMENT_SEPARATOR - _P9K_T[1]+="%f$_P9K_RETVAL" - _p9k_prompt_overflow_bug && _P9K_T[6]+='%{%G%}' + _p9k_prompt_overflow_bug && _P9K_T[2]+='%{%G%}' _P9K_RIGHT_SUFFIX+='%f%b%k' _P9K_RIGHT_PREFIX+='%f%b%k' - _p9k_get_icon RIGHT_SEGMENT_END_SEPARATOR - _p9k_escape_rcurly $_P9K_RETVAL - _P9K_RIGHT_PREFIX+=$_P9K_RETVAL - if [[ $POWERLEVEL9K_PROMPT_ON_NEWLINE == true ]]; then - _p9k_get_icon MULTILINE_FIRST_PROMPT_PREFIX + _p9k_get_icon '' MULTILINE_FIRST_PROMPT_PREFIX _P9K_LEFT_PREFIX+="$_P9K_RETVAL%f%b%k" - _p9k_get_icon MULTILINE_LAST_PROMPT_PREFIX + _p9k_get_icon '' MULTILINE_LAST_PROMPT_PREFIX _P9K_LEFT_SUFFIX+=$'\n'$_P9K_RETVAL'%f%b%k' if [[ $POWERLEVEL9K_RPROMPT_ON_NEWLINE != true && -o TRANSIENT_RPROMPT ]]; then if is-at-least 5.3; then @@ -2860,13 +3019,13 @@ _p9k_init() { POWERLEVEL9K_DIR_CLASSES=("${x[@]}") else typeset -ga POWERLEVEL9K_DIR_CLASSES=() - _p9k_get_icon ETC_ICON + _p9k_get_icon prompt_dir_ETC ETC_ICON POWERLEVEL9K_DIR_CLASSES+=('/etc|/etc/*' ETC "$_P9K_RETVAL") - _p9k_get_icon HOME_ICON + _p9k_get_icon prompt_dir_HOME HOME_ICON POWERLEVEL9K_DIR_CLASSES+=('~' HOME "$_P9K_RETVAL") - _p9k_get_icon HOME_SUB_ICON + _p9k_get_icon prompt_dir_HOME_SUBFOLDER HOME_SUB_ICON POWERLEVEL9K_DIR_CLASSES+=('~/*' HOME_SUBFOLDER "$_P9K_RETVAL") - _p9k_get_icon FOLDER_ICON + _p9k_get_icon prompt_dir_DEFAULT FOLDER_ICON POWERLEVEL9K_DIR_CLASSES+=('*' DEFAULT "$_P9K_RETVAL") fi fi |