diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/p10k.zsh | 749 |
1 files changed, 632 insertions, 117 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh index aa9fbdc7..68f78262 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -1367,7 +1367,7 @@ prompt_dir() { # for "~[a/b]" it'll give the nonsensical "~[a". To solve this problem we have to # repeat what "${(%):-%~}" does and hope that it produces the same result. local func='' - local -a parts=() + local -a parts=() reply=() for func in zsh_directory_name $zsh_directory_name_functions; do if (( $+functions[$func] )) && $func d $_p9k_pwd && [[ $p == '~['$reply[1]']'* ]]; then parts+='~['$reply[1]']' @@ -3905,7 +3905,7 @@ _p9k_set_instant_prompt() { RPROMPT=$saved_rprompt } -typeset -gri __p9k_instant_prompt_version=14 +typeset -gri __p9k_instant_prompt_version=16 _p9k_dump_instant_prompt() { local user=${(%):-%n} @@ -4011,12 +4011,51 @@ _p9k_dump_instant_prompt() { if (( _POWERLEVEL9K_SHOW_RULER )); then >&$fd print -r -- '[[ $P9K_TTY == old ]] && { unset _p9k__ruler_i; _p9k__display_v[4]=print }' fi + if (( $+functions[p10k-on-init] )); then + >&$fd print -r -- ' + p10k-on-init() { '$functions[p10k-on-init]' }' + fi + if (( $+functions[p10k-on-pre-prompt] )); then + >&$fd print -r -- ' + p10k-on-pre-prompt() { '$functions[p10k-on-pre-prompt]' }' + fi + if (( $+functions[p10k-on-post-prompt] )); then + >&$fd print -r -- ' + p10k-on-post-prompt() { '$functions[p10k-on-post-prompt]' }' + fi + if (( $+functions[p10k-on-post-widget] )); then + >&$fd print -r -- ' + p10k-on-post-widget() { '$functions[p10k-on-post-widget]' }' + fi + if (( $+functions[p10k-on-init] )); then + >&$fd print -r -- ' + p10k-on-init' + fi + local pattern segment + for pattern segment in $_p9k_show_on_command; do + >&$fd print -r -- " + _p9k__display_v[$((1+_p9k__display_k[$segment]))]=hide" + done + if (( $+functions[p10k-on-pre-prompt] )); then + >&$fd print -r -- ' + p10k-on-pre-prompt' + fi + if (( $+functions[p10k-on-init] )); then + >&$fd print -r -- ' + unfunction p10k-on-init' + fi if (( $+functions[p10k-on-pre-prompt] )); then >&$fd print -r -- ' - p10k-on-pre-prompt() { '$functions[p10k-on-pre-prompt]' } - p10k-on-pre-prompt unfunction p10k-on-pre-prompt' fi + if (( $+functions[p10k-on-post-prompt] )); then + >&$fd print -r -- ' + unfunction p10k-on-post-prompt' + fi + if (( $+functions[p10k-on-post-widget] )); then + >&$fd print -r -- ' + unfunction p10k-on-post-widget' + fi >&$fd print -r -- ' trap "unset -m _p9k__\*; unfunction p10k" EXIT local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}")' @@ -4434,7 +4473,6 @@ function _p9k_on_expand() { fi fi - _p9k__last_tty=$P9K_TTY __p9k_reset_state=1 if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE )); then @@ -4463,13 +4501,19 @@ function _p9k_on_expand() { fi fi - typeset -g P9K_PROMPT=regular - - if (( $+functions[p10k-on-pre-prompt] )); then - p10k-on-pre-prompt + if [[ -z $_p9k__last_tty ]]; then + _p9k_wrap_widgets + (( $+functions[p10k-on-init] )) && p10k-on-init fi + local pattern segment + for pattern segment in $_p9k_show_on_command; do + p10k display $segment=hide + done + (( $+functions[p10k-on-pre-prompt] )) && p10k-on-pre-prompt + __p9k_reset_state=0 + _p9k__last_tty=$P9K_TTY P9K_TTY=old if ! zle; then @@ -4585,7 +4629,7 @@ _p9k_trapint() { if (( __p9k_enabled )); then emulate -L zsh setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} - zle && _p9k_zle_line_finish int + zle && _p9k_on_widget_zle-line-finish int fi return 0 } @@ -4617,14 +4661,6 @@ function _p9k_reset_prompt() { fi } -function _p9k_zle_keymap_select() { - _p9k_reset_prompt -} - -function _p9k_zle_state_changed() { - _p9k_reset_prompt -} - _p9k_deinit_async_pump() { if (( _p9k__async_pump_lock_fd )); then zsystem flock -u $_p9k__async_pump_lock_fd @@ -4808,6 +4844,9 @@ typeset -g _p9k__param_pat typeset -g _p9k__param_sig _p9k_init_vars() { + typeset -ga _p9k_show_on_command + typeset -g _p9k__last_buffer + typeset -ga _p9k__last_commands typeset -g _p9k__last_tty typeset -gi _p9k__must_restore_prompt typeset -gi _p9k__restore_prompt_fd @@ -4931,6 +4970,7 @@ _p9k_init_vars() { typeset -g P9K_VISUAL_IDENTIFIER typeset -g P9K_CONTENT typeset -g P9K_GAP + typeset -g P9K_PROMPT=regular } _p9k_init_params() { @@ -4951,6 +4991,8 @@ _p9k_init_params() { _p9k_declare -s POWERLEVEL9K_TRANSIENT_PROMPT off [[ $_POWERLEVEL9K_TRANSIENT_PROMPT == (off|always|same-dir) ]] || _POWERLEVEL9K_TRANSIENT_PROMPT=off + _p9k_declare -i POWERLEVEL9K_COMMANDS_MAX_TOKEN_COUNT 64 + _p9k_declare -a POWERLEVEL9K_HOOK_WIDGETS -- _p9k_declare -b POWERLEVEL9K_TODO_HIDE_ZERO_TOTAL 0 _p9k_declare -b POWERLEVEL9K_TODO_HIDE_ZERO_FILTERED 0 _p9k_declare -b POWERLEVEL9K_DISABLE_HOT_RELOAD 0 @@ -5239,92 +5281,421 @@ _p9k_init_params() { done } -typeset -ga __p9k_wrapped_zle_widgets +typeset -grA __p9k_pb_cmd_skip=( + '}' 'always' # handled specially + '{' '' + '{' '' + '|' '' + '||' '' + '&' '' + '&&' '' + '|&' '' + '&!' '' + '&|' '' + ')' '' + '(' '' + '()' '' + '!' '' + ';' '' + 'if' '' + 'fi' '' + 'elif' '' + 'else' '' + 'then' '' + 'while' '' + 'until' '' + 'do' '' + 'done' '' + 'esac' '' + 'end' '' + 'coproc' '' + 'nocorrect' '' + 'noglob' '' + 'time' '' + '[[' '\]\]' + '((' '\)\)' + 'case' '\)|esac' + ';;' '\)|esac' + ';&' '\)|esac' + ';|' '\)|esac' + 'foreach' '\(*\)' +) -# _p9k_wrap_zle_widget zle-keymap-select _p9k_zle_keymap_select -_p9k_wrap_zle_widget() { - local widget=$1 - local hook=$2 - (( __p9k_wrapped_zle_widgets[(I)$widget:$hook] )) && return - __p9k_wrapped_zle_widgets+=$widget:$hook - local orig=p9k-orig-$widget - case $widgets[$widget] in - user:*) - zle -N $orig ${widgets[$widget]#user:} - ;; - builtin) - functions[_p9k_orig_$widget]="zle .${(q)widget}" - zle -N $orig _p9k_orig_$widget - ;; - esac +typeset -grA __p9k_pb_precommand=( + '-' '' + 'builtin' '' + 'command' '' + 'exec' '-[^a]#[a]' + 'nohup' '' + 'setsid' '' + 'eatmydata' '' + 'catchsegv' '' + 'pkexec' '--user' + 'doas' '-[^aCu]#[acU]' + 'nice' '-[^n]#[n]|--adjustment' + 'stdbuf' '-[^ioe]#[ioe]|--(input|output|error)' + 'sudo' '-[^aghpuUCcrtT]#[aghpuUCcrtT]|--(close-from|group|host|prompt|role|type|other-user|command-timeout|user)' +) - local wrapper=_p9k_wrapper_$widget_$hook - functions[$wrapper]=" - emulate -L zsh - setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} - (( __p9k_enabled )) && ${(q)hook} \"\$@\" - (( \$+widgets[${(q)orig}] )) && zle ${(q)orig} -- \"\$@\"" +typeset -grA __p9k_pb_redirect=( + '&>' '' + '>' '' + '>&' '' + '<' '' + '<&' '' + '<>' '' + '&>|' '' + '>|' '' + '&>>' '' + '>>' '' + '>>&' '' + '&>>|' '' + '>>|' '' + '<<<' '' +) - zle -N -- $widget $wrapper -} +typeset -grA __p9k_pb_term=( + '|' '' + '||' '' + ';' '' + '&' '' + '&&' '' + '|&' '' + '&!' '' + '&|' '' + ';;' '' + ';&' '' + ';|' '' + '(' '' + ')' '' + '()' '' # handled specially + '}' '' # handled specially +) -function _p9k_zle_line_init() { - (( _p9k__cursor_hidden )) || return 0 - _p9k__cursor_hidden=0 - echoti cnorm -} +typeset -grA __p9k_pb_term_skip=( + '(' '\)' + ';;' '\)|esac' + ';&' '\)|esac' + ';|' '\)|esac' +) + +# Usage: _p9k_parse_buffer <buffer> [token-limit] +# +# Parses the specified command line buffer and pupulates array P9K_COMMANDS +# with commands from it. Terminates early and returns 1 if there are more +# tokens than the specified limit. +# +# Broken: +# +# --------------- +# : $(x) +# --------------- +# : `x` +# --------------- +# ${x/} +# --------------- +# - -- x +# --------------- +# command -p -p x +# --------------- +# * +# --------------- +# x=$y; $x +# --------------- +# alias x=y; y +# --------------- +# x <<END +# ; END +# END +# --------------- +# Setup: +# setopt interactive_comments +# alias x='#' +# Punchline: +# x; y +# --------------- +# +# More brokenness with non-standard options (ignore_braces, ignore_close_braces, etc.). +function _p9k_parse_buffer() { + [[ ${2:-0} == <-> ]] || return 2 + + local rcquotes + [[ -o rcquotes ]] && rcquotes=(-o rcquotes) + + emulate -L zsh -o extended_glob -o no_nomatch $rcquotes + + typeset -ga P9K_COMMANDS=() + + local -r id='(<->|[[:alpha:]_][[:IDENT:]]#)' + local -r var="\$$id|\${$id}|\"\$$id\"|\"\${$id}\"" + + local -i e ic c=${2:-'1 << 62'} + local skip n s r state cmd prev + local -a aln alp alf v + + if [[ -o interactive_comments ]]; then + ic=1 + local tokens=(${(Z+C+)1}) + else + local tokens=(${(z)1}) + fi -function _p9k_restore_prompt() { - emulate -L zsh - setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} { - (( _p9k__must_restore_prompt )) || return - _p9k__must_restore_prompt=0 + while (( $#tokens )); do + (( e = $#state )) + + while (( $#tokens == alp[-1] )); do + aln[-1]=() + alp[-1]=() + if (( $#tokens == alf[-1] )); then + alf[-1]=() + (( e = 0 )) + fi + done - unset _p9k__line_finished - _p9k_refresh_reason=restore - _p9k_set_prompt - _p9k_refresh_reason= + while (( c-- > 0 )) || return; do + token=$tokens[1] + tokens[1]=() + if (( $+galiases[$token] )); then + (( $aln[(eI)p$token] )) && break + s=$galiases[$token] + n=p$token + elif (( e )); then + break + elif (( $+aliases[$token] )); then + (( $aln[(eI)p$token] )) && break + s=$aliases[$token] + n=p$token + elif [[ $token == ?*.?* ]] && (( $+saliases[${token##*.}] )); then + r=${token##*.} + (( $aln[(eI)s$r] )) && break + s=${saliases[$r]%% #} + n=s$r + else + break + fi + aln+=$n + alp+=$#tokens + [[ $s == *' ' ]] && alf+=$#tokens + (( ic )) && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s}) + done - local tty=$P9K_TTY - P9K_TTY=$_p9k__last_tty - _p9k__expanded=0 - _p9k_reset_prompt - P9K_TTY=$tty + case $token in + '<<'(|-)) + state=h + continue + ;; + '`'*'`'|'"`'*'`"'|'$('*')'|'"$('*')"'|['<>=']'('*')') + s=${${token##('"'|)(['$<>']|)?}%%?('"'|)} + (( ic )) && tokens+=(';' ${(Z+C+)s}) || tokens+=(';' ${(z)s}) + ;; + esac + + case $state in + *r) + state[-1]= + continue + ;; + a) + if [[ $token == $skip ]]; then + if [[ $token == '{' ]]; then + P9K_COMMANDS+=$cmd + cmd= + state= + else + skip='{' + fi + continue + else + state=t + fi + ;& # fall through + t|p*) + if (( $+__p9k_pb_term[$token] )); then + if [[ $token == '()' ]]; then + state= + else + P9K_COMMANDS+=$cmd + if [[ $token == '}' ]]; then + state=a + skip=always + else + skip=$__p9k_pb_term_skip[$token] + state=${skip:+s} + fi + fi + cmd= + continue + elif [[ $state == t ]]; then + continue + elif [[ $state == *x ]]; then + if (( $+__p9k_pb_redirect[$token] )); then + prev= + state[-1]=r + continue + else + state[-1]= + fi + fi + ;; + s) + if [[ $token == $~skip ]]; then + state= + fi + continue + ;; + h) + while (( $#tokens )); do + (( e = ${tokens[(i)${(Q)token}]} )) + if [[ $tokens[e-1] == ';' && $tokens[e+1] == ';' ]]; then + tokens[1,e]=() + break + else + tokens[1,e]=() + fi + done + while (( $#alp && alp[-1] >= $#tokens )); do + aln[-1]=() + alp[-1]=() + done + state=t + continue + ;; + esac + + if (( $+__p9k_pb_redirect[${token#<0-255>}] )); then + state+=r + continue + fi + + if [[ $token == *'$'* ]]; then + if [[ $token == $~var ]]; then + n=${${token##[^[:IDENT:]]}%%[^[:IDENT:]]} + [[ $token == *'"' ]] && v=("${(P)n}") || v=(${(P)n}) + tokens[1,0]=(${(qq)v}) + continue + fi + fi + + case $state in + '') + if (( $+__p9k_pb_cmd_skip[$token] )); then + skip=$__p9k_pb_cmd_skip[$token] + [[ $token == '}' ]] && state=a || state=${skip:+s} + continue + fi + if [[ $token == *=* ]]; then + v=${(S)token/#(<->|([[:alpha:]_][[:IDENT:]]#(|'['*[^\\](\\\\)#']')))(|'+')=} + if (( $#v < $#token )); then + if [[ $v == '(' ]]; then + state=s + skip='\)' + fi + continue + fi + fi + : ${token::=${(Q)${~token}}} + ;; + p2) + if [[ -n $prev ]]; then + prev= + else + : ${token::=${(Q)${~token}}} + if [[ $token == '{'$~id'}' ]]; then + state=p2x + prev=$token + else + state=p + fi + continue + fi + ;& # fall through + p) + if [[ -n $prev ]]; then + token=$prev + prev= + else + : ${token::=${(Q)${~token}}} + case $token in + '{'$~id'}') prev=$token; state=px; continue;; + [^-]*) ;; + --) state=p1; continue;; + $~skip) state=p2; continue;; + *) continue;; + esac + fi + ;; + p1) + if [[ -n $prev ]]; then + token=$prev + prev= + else + : ${token::=${(Q)${~token}}} + if [[ $token == '{'$~id'}' ]]; then + state=p1x + prev=$token + continue + fi + fi + ;; + esac + + if (( $+__p9k_pb_precommand[$token] )); then + prev= + state=p + skip=$__p9k_pb_precommand[$token] + cmd+=$token$'\0' + else + state=t + [[ $token == ('(('*'))'|'`'*'`'|'$'*|['<>=']'('*')'|*$'\0'*) ]] || cmd+=$token$'\0' + fi + done } always { - zle -F $1 - exec {1}>&- - _p9k__restore_prompt_fd=0 + [[ $state == (px|p1x) ]] && cmd+=$prev + P9K_COMMANDS+=$cmd + P9K_COMMANDS=(${(u)P9K_COMMANDS%$'\0'}) } } -function _p9k_zle_line_finish() { - [[ -z $1 && $CONTEXT != start ]] && _p9k__must_restore_prompt=0 +function _p9k_on_widget_zle-keymap-select() { __p9k_reset_state=2; } +function _p9k_on_widget_overwrite-mode() { __p9k_reset_state=2; } +function _p9k_on_widget_vi-replace() { __p9k_reset_state=2; } + +function _p9k_check_visual_mode() { + [[ ${KEYMAP:-} == vicmd ]] || return 0 + local region=${${REGION_ACTIVE:-0}/2/1} + [[ $region != $_p9k__region_active ]] || return 0 + _p9k__region_active=$region + __p9k_reset_state=2 +} +function _p9k_on_widget_visual-mode() { _p9k_check_visual_mode; } +function _p9k_on_widget_visual-line-mode() { _p9k_check_visual_mode; } +function _p9k_on_widget_deactivate-region() { _p9k_check_visual_mode; } + +function _p9k_on_widget_zle-line-init() { + (( _p9k__cursor_hidden )) || return 0 + _p9k__cursor_hidden=0 + echoti cnorm +} + +function _p9k_on_widget_zle-line-finish() { (( $+_p9k__line_finished )) && return _p9k__line_finished= - local -i reset=_p9k_reset_on_line_finish - - if (( $+functions[p10k-on-post-prompt] )); then - __p9k_reset_state=1 - p10k-on-post-prompt - if (( __p9k_reset_state == 2 )); then - reset=1 - fi - __p9k_reset_state=0 - fi + (( _p9k_reset_on_line_finish )) && __p9k_reset_state=2 + (( $+functions[p10k-on-post-prompt] )) && p10k-on-post-prompt if [[ -n $_p9k_transient_prompt ]]; then if [[ $_POWERLEVEL9K_TRANSIENT_PROMPT == always || $_p9k_pwd == $_p9k__last_prompt_pwd ]]; then RPROMPT= PROMPT=$_p9k_transient_prompt - reset=1 + __p9k_reset_state=2 else _p9k__last_prompt_pwd=$_p9k_pwd fi fi - if (( reset )); then + if (( __p9k_reset_state == 2 )); then if [[ $1 == int ]]; then _p9k__must_restore_prompt=1 if (( !_p9k__restore_prompt_fd )); then @@ -5337,17 +5708,123 @@ function _p9k_zle_line_finish() { echo -nE - $hide$'\n'$termcap[up] fi _p9k_reset_prompt + __p9k_reset_state=0 fi _p9k__line_finished='%{%}' } -function _p9k_zle_line_pre_redraw() { - [[ ${KEYMAP:-} == vicmd ]] || return 0 - local region=${${REGION_ACTIVE:-0}/2/1} - [[ $region != $_p9k__region_active ]] || return 0 - _p9k__region_active=$region - _p9k_reset_prompt +function _p9k_widget_hook() { + if (( $+functions[p10k-on-post-widget] || $#_p9k_show_on_command )); then + local -a P9K_COMMANDS + if [[ "$_p9k__last_buffer" == "$PREBUFFER$BUFFER" ]]; then + P9K_COMMANDS=(${_p9k__last_commands[@]}) + else + _p9k__last_buffer="$PREBUFFER$BUFFER" + if [[ -n "$_p9k__last_buffer" ]]; then + # this must run with user options + _p9k_parse_buffer "$_p9k__last_buffer" $_POWERLEVEL9K_COMMANDS_MAX_TOKEN_COUNT + fi + _p9k__last_commands=(${P9K_COMMANDS[@]}) + fi + fi + + emulate -L zsh + setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} + (( _p9k__restore_prompt_fd )) && _p9k_restore_prompt $_p9k__restore_prompt_fd + __p9k_reset_state=1 + local pattern segment + for pattern segment in $_p9k_show_on_command; do + if (( $P9K_COMMANDS[(I)$pattern] )); then + p10k display $segment=show + else + p10k display $segment=hide + fi + done + (( $+functions[p10k-on-post-widget] )) && p10k-on-post-widget "${@:2}" + (( $+functions[_p9k_on_widget_$1] )) && _p9k_on_widget_$1 + (( __p9k_reset_state == 2 )) && _p9k_reset_prompt + __p9k_reset_state=0 +} + +function _p9k_widget() { + (( ! ${+widgets[._p9k_orig_$1]} )) || zle ._p9k_orig_$1 "${@:2}" + local res=$? + (( ! __p9k_enabled )) || [[ $CONTEXT != start ]] || _p9k_widget_hook "$@" + return res +} + +typeset -gi __p9k_widgets_wrapped=0 + +function _p9k_wrap_widgets() { + (( __p9k_widgets_wrapped )) && return + typeset -gir __p9k_widgets_wrapped=1 + local -a widget_list + if is-at-least 5.3; then + local -aU widget_list=( + zle-line-pre-redraw + zle-line-init + zle-line-finish + zle-keymap-select + overwrite-mode + vi-replace + visual-mode + visual-line-mode + deactivate-region + $_POWERLEVEL9K_HOOK_WIDGETS + ) + else + # There is no zle-line-pre-redraw in zsh < 5.3, so we have to wrap all widgets + # with key bindings. This costs extra 3ms: 1.5ms to fetch the list of widgets and + # another 1.5ms to wrap them. + local keymap tmp=${TMPDIR:-/tmp}/p10k.bindings.$sysparams[pid] + { + for keymap in $keymaps; do bindkey -M $keymap; done >$tmp + local -aU widget_list=( + zle-isearch-exit + zle-isearch-update + zle-line-init + zle-line-finish + zle-history-line-set + zle-keymap-select + $_POWERLEVEL9K_HOOK_WIDGETS + ${${${(f)"$(<$tmp)"}##* }:#(*\"|.*)} + ) + } always { + zf_rm -f $tmp + } + fi + local widget + for widget in $widget_list; do + functions[_p9k_widget_$widget]='_p9k_widget '${(q)widget}' "$@"' + # The leading dot is to work around bugs in zsh-syntax-highlighting. + zle -A $widget ._p9k_orig_$widget + zle -N $widget _p9k_widget_$widget + done 2>/dev/null # `zle -A` fails for inexisting widgets and complains to stderr +} + +function _p9k_restore_prompt() { + emulate -L zsh + setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} + { + (( _p9k__must_restore_prompt )) || return + _p9k__must_restore_prompt=0 + + unset _p9k__line_finished + _p9k_refresh_reason=restore + _p9k_set_prompt + _p9k_refresh_reason= + + local tty=$P9K_TTY + P9K_TTY=$_p9k__last_tty + _p9k__expanded=0 + _p9k_reset_prompt + P9K_TTY=$tty + } always { + zle -F $1 + exec {1}>&- + _p9k__restore_prompt_fd=0 + } } prompt__p9k_internal_nothing() { _p9k__prompt+='${_p9k_sss::=}'; } @@ -5696,7 +6173,7 @@ _p9k_must_init() { [[ $sig == $_p9k__param_sig ]] && return 1 _p9k_deinit fi - _p9k__param_pat=$'v22\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' + _p9k__param_pat=$'v25\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' _p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1' _p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1' _p9k__param_pat+=$'$DEFAULT_USER\1${ZLE_RPROMPT_INDENT:-1}\1$P9K_SSH\1$__p9k_ksh_arrays' @@ -5720,6 +6197,23 @@ function _p9k_init_cacheable() { _p9k_init_params _p9k_init_prompt + local elem + local -i i=0 + + for i in {1..$#_p9k_line_segments_left}; do + for elem in ${(@0)_p9k_line_segments_left[i]}; do + local var=POWERLEVEL9K_${(U)elem}_SHOW_ON_COMMAND + (( $+parameters[$var] )) || continue + _p9k_show_on_command+=($'(|*[/\0])('${(j.|.)${(P)var}}')' $i/left/$elem) + done + for elem in ${(@0)_p9k_line_segments_right[i]}; do + local var=POWERLEVEL9K_${(U)elem}_SHOW_ON_COMMAND + (( $+parameters[$var] )) || continue + local cmds=(${(P)var}) + _p9k_show_on_command+=($'(|*[/\0])('${(j.|.)${(P)var}}')' $i/right/$elem) + done + done + if [[ $_POWERLEVEL9K_TRANSIENT_PROMPT != off ]]; then _p9k_transient_prompt='%b%k%s%u%F{%(?.' _p9k_color prompt_prompt_char_OK_VIINS FOREGROUND 76 @@ -5799,14 +6293,13 @@ function _p9k_init_cacheable() { 'DISCONNECTED' "$_p9k_color2" ) - local -i i=0 # This simpler construct doesn't work on zsh-5.1 with multi-line prompt: # # ${(@0)_p9k_line_segments_left[@]} local -a left_segments=(${(@0)${(pj:\0:)_p9k_line_segments_left}}) _p9k_left_join=(1) for ((i = 2; i <= $#left_segments; ++i)); do - local elem=$left_segments[i] + elem=$left_segments[i] if [[ $elem == *_joined ]]; then _p9k_left_join+=$_p9k_left_join[((i-1))] else @@ -5817,7 +6310,7 @@ function _p9k_init_cacheable() { local -a right_segments=(${(@0)${(pj:\0:)_p9k_line_segments_right}}) _p9k_right_join=(1) for ((i = 2; i <= $#right_segments; ++i)); do - local elem=$right_segments[i] + elem=$right_segments[i] if [[ $elem == *_joined ]]; then _p9k_right_join+=$_p9k_right_join[((i-1))] else @@ -5997,23 +6490,6 @@ _p9k_init() { fi fi - _p9k_wrap_zle_widget zle-line-finish _p9k_zle_line_finish - _p9k_wrap_zle_widget zle-line-init _p9k_zle_line_init - - if _p9k_segment_in_use vi_mode || _p9k_segment_in_use prompt_char; then - _p9k_wrap_zle_widget zle-keymap-select _p9k_zle_keymap_select - fi - - if _p9k_segment_in_use vi_mode && (( $+_POWERLEVEL9K_VI_VISUAL_MODE_STRING )) || _p9k_segment_in_use prompt_char; then - _p9k_wrap_zle_widget zle-line-pre-redraw _p9k_zle_line_pre_redraw - fi - - if { _p9k_segment_in_use vi_mode && (( $+_POWERLEVEL9K_VI_OVERWRITE_MODE_STRING )) } || - { _p9k_segment_in_use prompt_char && (( _POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE )) }; then - _p9k_wrap_zle_widget overwrite-mode _p9k_zle_state_changed - _p9k_wrap_zle_widget vi-replace _p9k_zle_state_changed - fi - if _p9k_segment_in_use dir && [[ $_POWERLEVEL9K_SHORTEN_STRATEGY == truncate_with_package_name && $+commands[jq] == 0 ]]; then print -rP -- '%F{yellow}WARNING!%f %BPOWERLEVEL9K_SHORTEN_STRATEGY=truncate_with_package_name%b requires %F{green}jq%f.' @@ -6213,9 +6689,15 @@ typeset -gr __p9k_p10k_display_usage="Usage: %2Fp10k%f %Bdisplay%b part-pattern= Show, hide or toggle prompt parts. If called from zle, the current prompt is refreshed. +Usage: %2Fp10k%f %Bdisplay%b -a [part-pattern]... + +Populate array \\\`reply\\\` with states of prompt parts matching the patterns. +If no patterns are supplied, assume \\\`*\\\`. + Parts: empty_line empty line (duh) - ruler ruler; if POWERLEVEL9K_RULER_CHAR=' ', it's essentially another new_line + ruler ruler; if POWERLEVEL9K_RULER_CHAR=' ', it's essentially another + new_line N prompt line number N, 1-based; counting from the top if positive, from the bottom if negative N/left_frame left frame on the Nth line @@ -6230,14 +6712,31 @@ Part States: show the part is displayed hide the part is not displayed print the part is printed in precmd; only applicable to empty_line and - ruler; looks better than show after clear; unlike show, the effects - of print cannot be undone with hide + ruler; looks better than show after calling \\\`clear\\\`; unlike + show, the effects of print cannot be undone with hide + +part-pattern is a glob pattern for parts. Examples: + + */kubecontext all kubecontext prompt segments, regardless of where + they are + 1/(right|right_frame) all prompt segments and frame from the right side of + the first line + +state-list is a comma-separated list of states. Must have at least one element. +If more than one, states will rotate. Example: Bind Ctrl+P to toggle right prompt. function toggle-right-prompt() { p10k display '*/right'=hide,show; } zle -N toggle-right-prompt - bindkey '^P' toggle-right-prompt" + bindkey '^P' toggle-right-prompt + +Example: Print the state of all prompt parts: + + local -A reply + p10k display -a '*' + printf '%%32s = %%q\n' \\\${(@kv)reply} +" # 0 -- reset-prompt not blocked # 1 -- reset-prompt blocked and not needed @@ -6258,7 +6757,8 @@ function p10k() { case $1 in segment) shift - local opt state bg=0 fg icon cond text ref=0 expand=0 + local -i OPTIND + local OPTARG opt state bg=0 fg icon cond text ref=0 expand=0 while getopts ':s:b:f:i:c:t:reh' opt; do case $opt in s) state=$OPTARG;; @@ -6299,14 +6799,28 @@ function p10k() { print -rP -- $__p9k_p10k_display_usage >&2 return 1 fi - if [[ $2 == -h ]]; then - print -rP -- $__p9k_p10k_display_usage >&2 + shift + local -i OPTIND k dump + local OPTARG opt match MATCH prev new pair list name var + while getopts ':ha' opt; do + case $opt in + a) dump=1;; + h) print -rP -- $__p9k_p10k_display_usage; return 0;; + ?) print -rP -- $__p9k_p10k_display_usage >&2; return 1;; + esac + done + if (( dump )); then + reply=() + shift $((OPTIND-1)) + (( ARGC )) || set -- '*' + for opt; do + for k in ${(u@)_p9k__display_k[(I)$opt]:/(#m)*/$_p9k__display_k[$MATCH]}; do + reply+=($_p9k__display_v[k,k+1]) + done + done return 0 fi - shift - local opt match MATCH prev new pair list name var - local -i k - for opt; do + for opt in "${@:$OPTIND}"; do pair=(${(s:=:)opt}) list=(${(s:,:)${pair[2]}}) for k in ${(u@)_p9k__display_k[(I)$pair[1]]:/(#m)*/$_p9k__display_k[$MATCH]}; do @@ -6392,6 +6906,7 @@ zmodload zsh/parameter 2>/dev/null # https://github.com/romkatv/gitstatus/issue zmodload zsh/system zmodload zsh/termcap zmodload zsh/terminfo +zmodload zsh/zleparameter zmodload -F zsh/stat b:zstat zmodload -F zsh/net/socket b:zsocket zmodload -F zsh/files b:zf_mv b:zf_rm |