aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/p10k.zsh363
1 files changed, 300 insertions, 63 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index b54add4c..97ccb271 100644
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -260,7 +260,7 @@ _p9k_cache_set() {
# echo "caching: ${(@0q)_p9k_cache_key} => (${(q)@})" >&2
_p9k_cache[$_p9k_cache_key]="${(pj:\0:)*}0"
_p9k_cache_val=("$@")
- _p9k_dump_scheduled=1
+ _p9k_state_dump_scheduled=1
}
_p9k_cache_get() {
@@ -269,6 +269,19 @@ _p9k_cache_get() {
[[ -n $v ]] && _p9k_cache_val=("${(@0)${v[1,-2]}}")
}
+_p9k_cache_ephemeral_set() {
+ # Uncomment to see cache misses.
+ # echo "caching: ${(@0q)_p9k_cache_key} => (${(q)@})" >&2
+ _p9k_cache_ephemeral[$_p9k_cache_key]="${(pj:\0:)*}0"
+ _p9k_cache_val=("$@")
+}
+
+_p9k_cache_ephemeral_get() {
+ _p9k_cache_key="${(pj:\0:)*}"
+ local v=$_p9k_cache_ephemeral[$_p9k_cache_key]
+ [[ -n $v ]] && _p9k_cache_val=("${(@0)${v[1,-2]}}")
+}
+
_p9k_cache_stat_get() {
local -H stat
local label=$1 f
@@ -549,12 +562,20 @@ _p9k_left_prompt_segment() {
local join="_p9k_i>=$_p9k_left_join[$_p9k_segment_index]"
_p9k_param $1 SELF_JOINED false
- [[ $_p9k_ret == false ]] && join+="&&_p9k_i<$_p9k_segment_index"
+ if [[ $_p9k_ret == false ]]; then
+ if (( _p9k_segment_index > $_p9k_left_join[$_p9k_segment_index] )); then
+ join+="&&_p9k_i<$_p9k_segment_index"
+ else
+ join=
+ fi
+ fi
local p=
p+="\${_p9k_n::=}"
p+="\${\${\${_p9k_bg:-0}:#NONE}:-\${_p9k_n::=$((t+1))}}" # 1
- p+="\${_p9k_n:=\${\${\$(($join)):#0}:+$((t+2))}}" # 2
+ if [[ -n $join ]]; then
+ p+="\${_p9k_n:=\${\${\$(($join)):#0}:+$((t+2))}}" # 2
+ fi
if (( __p9k_sh_glob )); then
p+="\${_p9k_n:=\${\${(M)\${:-x$bg_color}:#x\$_p9k_bg}:+$((t+3))}}" # 3
p+="\${_p9k_n:=\${\${(M)\${:-x$bg_color}:#x\$${_p9k_bg:-0}}:+$((t+3))}}" # 3
@@ -755,7 +776,13 @@ _p9k_right_prompt_segment() {
local join="_p9k_i>=$_p9k_right_join[$_p9k_segment_index]"
_p9k_param $1 SELF_JOINED false
- [[ $_p9k_ret == false ]] && join+="&&_p9k_i<$_p9k_segment_index"
+ if [[ $_p9k_ret == false ]]; then
+ if (( _p9k_segment_index > $_p9k_right_join[$_p9k_segment_index] )); then
+ join+="&&_p9k_i<$_p9k_segment_index"
+ else
+ join=
+ fi
+ fi
local p=
p+="\${_p9k_n::=}"
@@ -1143,7 +1170,7 @@ prompt_context() {
local -i enabled=1
local content
if [[ $_POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == 0 && -n $DEFAULT_USER && $P9K_SSH == 0 ]]; then
- local user="$(whoami)"
+ local user="${(%):-%n}"
if [[ $user == $DEFAULT_USER ]]; then
if (( _POWERLEVEL9K_ALWAYS_SHOW_USER )); then
content="${user//\%/%%}"
@@ -1187,11 +1214,13 @@ prompt_context() {
_p9k_prompt_segment "$0_$_p9k_cache_val[2]" "$_p9k_color1" yellow '' 0 '' "$_p9k_cache_val[3]"
}
+instant_prompt_context() { prompt_context; }
+
################################################################
# User: user (who am I)
prompt_user() {
if ! _p9k_cache_get $0 "${(%):-%#}"; then
- local user="$(whoami)"
+ local user="${(%):-%n}"
if [[ $_POWERLEVEL9K_ALWAYS_SHOW_USER == 0 && $user == $DEFAULT_USER ]]; then
_p9k_cache_set true
elif [[ "${(%):-%#}" == '#' ]]; then
@@ -1205,6 +1234,8 @@ prompt_user() {
"$_p9k_cache_val[@]"
}
+instant_prompt_user() { prompt_user; }
+
################################################################
# Host: machine (where am I)
prompt_host() {
@@ -1215,6 +1246,8 @@ prompt_host() {
fi
}
+instant_prompt_host() { prompt_host; }
+
################################################################
# The 'custom` prompt provides a way for users to invoke commands and display
# the output in a segment.
@@ -1408,7 +1441,7 @@ prompt_dir() {
else
local mtime='good'
fi
- if ! _p9k_cache_get $0 "${parts[@]}" || [[ -z $mtime || $mtime != $_p9k_cache_val[1] ]] ; then
+ if ! _p9k_cache_ephemeral_get $0 "${parts[@]}" || [[ -z $mtime || $mtime != $_p9k_cache_val[1] ]] ; then
_p9k_prompt_length $delim
local -i real_delim_len=_p9k_ret n=1 q=0
[[ -n $parts[i-1] ]] && parts[i-1]="\${(Q)\${:-${(qqq)${(q)parts[i-1]}}}}"$'\2'
@@ -1448,7 +1481,7 @@ prompt_dir() {
(( q )) && parts[i]='${(Q)${:-'${(qqq)${(q)parts[i]}}'}}'
parts[i]+=$'\2'
done
- _p9k_cache_set "$mtime" "${parts[@]}"
+ _p9k_cache_ephemeral_set "$mtime" "${parts[@]}"
fi
parts=("${(@)_p9k_cache_val[2,-1]}")
;;
@@ -1480,7 +1513,7 @@ prompt_dir() {
[[ $_POWERLEVEL9K_DIR_SHOW_WRITABLE == 1 && ! -w $_p9k_pwd ]]
local w=$?
- if ! _p9k_cache_get $0 $_p9k_pwd $p $w $fake_first "${parts[@]}"; then
+ if ! _p9k_cache_ephemeral_get $0 $_p9k_pwd $p $w $fake_first "${parts[@]}"; then
local state=$0
local icon=''
if (( ! w )); then
@@ -1589,7 +1622,7 @@ prompt_dir() {
fi
(( expand )) && _p9k_prompt_length "${(e):-"\${\${_p9k_d::=0}+}$content"}" || _p9k_ret=
- _p9k_cache_set "$state" "$icon" "$expand" "$content" $_p9k_ret
+ _p9k_cache_ephemeral_set "$state" "$icon" "$expand" "$content" $_p9k_ret
fi
if (( _p9k_cache_val[3] )); then
@@ -1604,6 +1637,8 @@ prompt_dir() {
_p9k_prompt_segment "$_p9k_cache_val[1]" "blue" "$_p9k_color1" "$_p9k_cache_val[2]" "$_p9k_cache_val[3]" "" "$_p9k_cache_val[4]"
}
+instant_prompt_dir() { prompt_dir; }
+
################################################################
# Docker machine
prompt_docker_machine() {
@@ -1958,6 +1993,8 @@ prompt_os_icon() {
_p9k_prompt_segment "$0" "black" "white" '' 0 '' "$_p9k_os_icon"
}
+instant_prompt_os_icon() { prompt_os_icon; }
+
################################################################
# Segment to display PHP version number
prompt_php_version() {
@@ -2105,6 +2142,8 @@ prompt_ssh() {
fi
}
+instant_prompt_ssh() { prompt_ssh; }
+
################################################################
# Status: When an error occur, return the error code, or a cross icon if option is set
# Display an ok icon when no error occur, or hide the segment if option is set to false
@@ -2147,6 +2186,12 @@ prompt_status() {
_p9k_prompt_segment "${(@)_p9k_cache_val}"
}
+instant_prompt_status() {
+ if (( _POWERLEVEL9K_STATUS_OK )); then
+ _p9k_prompt_segment prompt_status_OK "$_p9k_color1" green OK_ICON 0 '' ''
+ fi
+}
+
prompt_prompt_char() {
if (( __p9k_sh_glob )); then
if (( _p9k_status )); then
@@ -2191,6 +2236,10 @@ prompt_prompt_char() {
fi
}
+instant_prompt_prompt_char() {
+ _p9k_prompt_segment prompt_char_OK_VIINS "$_p9k_color1" 76 '' 0 '' '❯'
+}
+
################################################################
# Segment to display Swap information
prompt_swap() {
@@ -2274,6 +2323,10 @@ prompt_time() {
fi
}
+instant_prompt_time() {
+ _p9k_prompt_segment prompt_time "$_p9k_color2" "$_p9k_color1" "TIME_ICON" 0 '' "$_POWERLEVEL9K_TIME_FORMAT"
+}
+
################################################################
# System date
prompt_date() {
@@ -2281,6 +2334,10 @@ prompt_date() {
_p9k_prompt_segment "$0" "$_p9k_color2" "$_p9k_color1" "DATE_ICON" 0 '' "$d"
}
+instant_prompt_date() {
+ _p9k_prompt_segment prompt_date "$_p9k_color2" "$_p9k_color1" "DATE_ICON" 0 '' "$_POWERLEVEL9K_DATE_FORMAT"
+}
+
################################################################
# todo.sh: shows the number of tasks in your todo.sh file
prompt_todo() {
@@ -2640,7 +2697,7 @@ function _p9k_vcs_render() {
cache_key+=$VCS_STATUS_COMMIT
fi
- if ! _p9k_cache_get "$state" "${(@)cache_key}"; then
+ if ! _p9k_cache_ephemeral_get "$state" "${(@)cache_key}"; then
local icon
local content
@@ -2747,7 +2804,7 @@ function _p9k_vcs_render() {
fi
fi
- _p9k_cache_set "prompt_vcs_$state" "${__p9k_vcs_states[$state]}" "$_p9k_color1" "$icon" 0 '' "$content"
+ _p9k_cache_ephemeral_set "prompt_vcs_$state" "${__p9k_vcs_states[$state]}" "$_p9k_color1" "$icon" 0 '' "$content"
fi
_p9k_prompt_segment "$_p9k_cache_val[@]"
@@ -2907,6 +2964,12 @@ prompt_vi_mode() {
fi
}
+instant_prompt_vi_mode() {
+ if [[ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then
+ _p9k_prompt_segment prompt_vi_mode_INSERT "$_p9k_color1" blue '' 0 '' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING"
+ fi
+}
+
################################################################
# Virtualenv: current working virtualenv
# More information on virtualenv (Python):
@@ -3220,6 +3283,10 @@ function prompt_ranger() {
_p9k_prompt_segment $0 $_p9k_color1 yellow RANGER_ICON 0 '' $RANGER_LEVEL
}
+function instant_prompt_ranger() {
+ _p9k_prompt_segment prompt_ranger $_p9k_color1 yellow RANGER_ICON 1 '$RANGER_LEVEL' '$RANGER_LEVEL'
+}
+
function prompt_terraform() {
(( $+commands[terraform] )) || return
local ws=default
@@ -3281,6 +3348,15 @@ function _p9k_build_segment() {
((++_p9k_segment_index))
}
+function _p9k_build_instant_segment() {
+ _p9k_segment_name=${_p9k_segment_name%_joined}
+ if (( $+functions[instant_prompt_$_p9k_segment_name] )); then
+ # TODO: Drop segment if it has '$(' in CONTEXT_EXPANSION or VISUAL_IDENTIFIER_EXPANSION.
+ instant_prompt_$_p9k_segment_name
+ fi
+ ((++_p9k_segment_index))
+}
+
function _p9k_set_prompt() {
local ifs=$IFS
IFS=$' \t\n\0'
@@ -3300,8 +3376,9 @@ function _p9k_set_prompt() {
_p9k_segment_index=right_idx
_p9k_prompt_side=right
for _p9k_segment_name in ${(@0)_p9k_line_segments_right[i]}; do
- _p9k_build_segment
+ _p9k_build_${1}segment
done
+ _p9k_prompt=${${_p9k_prompt//$' %{\b'/'%{%G'}//$' \b'}
right_idx=_p9k_segment_index
if [[ -n $_p9k_prompt || $_p9k_line_never_empty_right[i] == 1 ]]; then
right=$_p9k_line_prefix_right[i]$_p9k_prompt$_p9k_line_suffix_right[i]
@@ -3312,22 +3389,23 @@ function _p9k_set_prompt() {
_p9k_segment_index=left_idx
_p9k_prompt_side=left
for _p9k_segment_name in ${(@0)_p9k_line_segments_left[i]}; do
- _p9k_build_segment
+ _p9k_build_${1}segment
done
+ _p9k_prompt=${${_p9k_prompt//$' %{\b'/'%{%G'}//$' \b'}
left_idx=_p9k_segment_index
_p9k_prompt+=$_p9k_line_suffix_left[i]
if (( $+_p9k_dir || (i != num_lines && $#right) )); then
- PROMPT+='${${:-${_p9k_d::=0}${_p9k_rprompt::='
- [[ -o transient_rprompt ]] && PROMPT+='${_p9k_line_finished-'$right'}' || PROMPT+=$right
- PROMPT+='}${_p9k_lprompt::='$_p9k_prompt'}}+}'
- PROMPT+=$_p9k_gap_pre
+ local p='${${:-${_p9k_d::=0}${_p9k_rprompt::='
+ [[ -o transient_rprompt ]] && p+='${_p9k_line_finished-'$right'}' || p+=$right
+ _p9k_prompt=$p'}${_p9k_lprompt::='$_p9k_prompt'}}+}'
+ _p9k_prompt+=$_p9k_gap_pre
if (( $+_p9k_dir )); then
if (( i == num_lines && (_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS > 0 || _POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT > 0) )); then
local a=$_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS
local f=$((0.01*_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT))'*_p9k_clm'
- PROMPT+="\${\${_p9k_g::=$((($a<$f)*$f+($a>=$f)*$a))}+}"
+ _p9k_prompt+="\${\${_p9k_g::=$((($a<$f)*$f+($a>=$f)*$a))}+}"
else
- PROMPT+='${${_p9k_g::=0}+}'
+ _p9k_prompt+='${${_p9k_g::=0}+}'
fi
if [[ $_POWERLEVEL9K_DIR_MAX_LENGTH == <->('%'|) ]]; then
local lim=
@@ -3338,37 +3416,150 @@ function _p9k_set_prompt() {
((lim <= 0)) && lim=
fi
if [[ -n $lim ]]; then
- PROMPT+='${${${$((_p9k_g<_p9k_m+'$lim')):#1}:-${_p9k_g::=$((_p9k_m+'$lim'))}}+}'
+ _p9k_prompt+='${${${$((_p9k_g<_p9k_m+'$lim')):#1}:-${_p9k_g::=$((_p9k_m+'$lim'))}}+}'
fi
fi
- PROMPT+='${${_p9k_d::=$((_p9k_m-_p9k_g))}+}'
- PROMPT+='${_p9k_lprompt/\%\{d\%\}*\%\{d\%\}/'$_p9k_dir'}'
- PROMPT+='${${_p9k_m::=$((_p9k_d+_p9k_g))}+}'
+ _p9k_prompt+='${${_p9k_d::=$((_p9k_m-_p9k_g))}+}'
+ _p9k_prompt+='${_p9k_lprompt/\%\{d\%\}*\%\{d\%\}/'$_p9k_dir'}'
+ _p9k_prompt+='${${_p9k_m::=$((_p9k_d+_p9k_g))}+}'
else
- PROMPT+='${_p9k_lprompt}'
+ _p9k_prompt+='${_p9k_lprompt}'
fi
- ((i != num_lines && $#right)) && PROMPT+=$_p9k_line_gap_post[i]
- else
- PROMPT+=$_p9k_prompt
+ ((i != num_lines && $#right)) && _p9k_prompt+=$_p9k_line_gap_post[i]
fi
if (( i == num_lines )); then
- RPROMPT=$right
- elif [[ -z $right ]]; then
- PROMPT+=$'\n'
+ [[ -n $right ]] && RPROMPT=$_p9k_prompt_prefix_right$right$_p9k_prompt_suffix_right
+ _p9k_prompt+=$_p9k_prompt_suffix_left
+ [[ $1 == instant_ ]] || PROMPT+=$_p9k_prompt
+ else
+ PROMPT+=$_p9k_prompt
+ [[ -n $right ]] || PROMPT+=$'\n'
fi
done
- PROMPT=${${PROMPT//$' %{\b'/'%{%G'}//$' \b'}
- RPROMPT=${${RPROMPT//$' %{\b'/'%{%G'}//$' \b'}
-
- PROMPT+=$_p9k_prompt_suffix_left
- [[ -n $RPROMPT ]] && RPROMPT=$_p9k_prompt_prefix_right$RPROMPT$_p9k_prompt_suffix_right
-
_p9k_prompt_side=
(( $#_p9k_cache < _POWERLEVEL9K_MAX_CACHE_SIZE )) || _p9k_cache=()
+ (( $#_p9k_cache_ephemeral < _POWERLEVEL9K_MAX_CACHE_SIZE )) || _p9k_cache_ephemeral=()
IFS=$ifs
}
+_p9k_set_instant_prompt() {
+ local saved_prompt=$PROMPT
+ local saved_rprompt=$RPROMPT
+ _p9k_set_prompt instant_
+ typeset -g _p9k_instant_prompt=$PROMPT$'\x1f'$_p9k_prompt$'\x1f'$RPROMPT
+ PROMPT=$saved_prompt
+ RPROMPT=$saved_rprompt
+}
+
+_p9k_dump_instant_prompt() {
+ is-at-least 5.4 || return # `typeset -g` doesn't roundtrip in zsh prior to 5.4.
+ local user=${(%):-%n}
+ local root_dir=${__p9k_dump_file:h}
+ local prompt_dir=${root_dir}/powerlevel10k-$user
+ local root_file=$root_dir/p10k-instant-prompt-$user.zsh
+ local prompt_file=$prompt_dir/prompt-${#_p9k_pwd}
+ [[ -d $prompt_dir ]] || mkdir -p $prompt_dir || return
+ [[ -w $root_dir && -w $prompt_dir ]] || return
+
+ if [[ ! -e $root_file ]]; then
+ local tmp=$root_file.tmp.$$
+ local -i fd
+ sysopen -a -o creat,trunc -u fd $tmp || return
+ {
+ >&$fd print -r -- "() {
+ emulate -L zsh
+ (( ! \$+__p9k_instant_prompt_disabled )) || return
+ typeset -gi __p9k_instant_prompt_disabled=1 __p9k_instant_prompt_sourced=1
+ [[ -t 0 && -t 1 && -t 2 && \$ZSH_VERSION == ${(q)ZSH_VERSION} && \$ZSH_PATCHLEVEL == ${(q)ZSH_PATCHLEVEL} ]] || return
+ local -i ZLE_RPROMPT_INDENT=${ZLE_RPROMPT_INDENT:-1}
+ local PROMPT_EOL_MARK=${(q)PROMPT_EOL_MARK-%B%S%#%s%b}
+ [[ -n \$SSH_CLIENT || -n \$SSH_TTY || -n \$SSH_CONNECTION ]] && local ssh=1 || local ssh=0
+ local cr=\$'\r' lf=\$'\n' esc=\$'\e[' rs=$'\x1e' us=$'\x1f'
+ local -i height=$_POWERLEVEL9K_INSTANT_PROMPT_COMMAND_LINES
+ local prompt_dir=${(q)prompt_dir}
+ zmodload zsh/langinfo
+ if [[ \${langinfo[CODESET]:-} != (utf|UTF)(-|)8 ]]; then
+ local lc=${(q)${${${_p9k_locale:-${(M)LC_CTYPE:#*.(utf|UTF)(-|)8}}:-${(M)LC_ALL:#*.(utf|UTF)(-|)8}}}:-${(M)LANG:#*.(utf|UTF)(-|)8}}
+ local LC_ALL=\${lc:-\${\${(@M)\$(locale -a 2>/dev/null):#*.(utf|UTF)(-|)8}[1]:-en_US.UTF-8}}
+ fi"
+ >&$fd print -r -- '
+ zmodload zsh/terminfo
+ (( $+terminfo[cuu] && $+terminfo[cuf] && $+terminfo[sgr0] && $+terminfo[ed] && $+terminfo[sc] && $+terminfo[rc] )) || return
+ local pwd=${(%):-%/}
+ local prompt_file=$prompt_dir/prompt-${#pwd}
+ local key=$pwd:$ssh:${(%):-%#}
+ local content
+ { content="$(<$prompt_file)" } 2>/dev/null || return
+ local tail=${content##*$rs$key$us}
+ [[ ${#tail} != ${#content} ]] || return
+ local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}")
+ typeset -ga __p9k_used_instant_prompt=("${(@e)_p9k_t[-3,-1]}")
+ local _p9k_ret=
+ function _p9k_prompt_length() {
+ local COLUMNS=1024
+ local -i x y=$#1 m
+ if (( y )); then
+ while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
+ x=y
+ (( y *= 2 ));
+ done
+ local xy
+ while (( y > x + 1 )); do
+ m=$(( x + (y - x) / 2 ))
+ typeset ${${(%):-$1%$m(l.x.y)}[-1]}=$m
+ done
+ fi
+ _p9k_ret=$x
+ }
+ _p9k_prompt_length "$PROMPT_EOL_MARK"
+ local -i fill=$((COLUMNS-_p9k_ret))
+ : ${__p9k_used_instant_prompt[1]//$lf/$((++height))}
+ local out="${(%):-$PROMPT_EOL_MARK${(pl.$fill.. .)}$cr%b%k%f%E}${(pl.$height..$lf.)}$esc${height}A$terminfo[sc]"
+ out+=${(%):-"$__p9k_used_instant_prompt[1]$__p9k_used_instant_prompt[2]"}
+ if [[ -n $__p9k_used_instant_prompt[3] ]]; then
+ _p9k_prompt_length "$__p9k_used_instant_prompt[2]"
+ local -i left_len=_p9k_ret
+ _p9k_prompt_length "$__p9k_used_instant_prompt[3]"
+ local -i gap=$((COLUMNS - left_len - _p9k_ret - ZLE_RPROMPT_INDENT))
+ if (( gap >= 40 )); then
+ out+="${(pl.$gap.. .)}${(%)${__p9k_used_instant_prompt[3]}}$terminfo[sgr0]$cr$esc${left_len}C"
+ fi
+ fi
+ { echo -n >${TMPDIR:-/tmp}/p10k-instant-prompt-output-$$ } || return
+ print -rn -- "$out" || return
+ exec {__p9k_fd_1}>&1 {__p9k_fd_2}>&2 1>${TMPDIR:-/tmp}/p10k-instant-prompt-output-$$
+ exec 2>&1
+ typeset -gi __p9k_instant_prompt_active=1
+ function _p9k_instant_prompt_precmd_first() {
+ emulate -L zsh
+ function _p9k_instant_prompt_sched_last() {
+ emulate -L zsh
+
+ }
+ zmodload zsh/sched
+ sched +0 _p9k_instant_prompt_sched_last
+ precmd_functions=(${(@)precmd_functions:#_p9k_instant_prompt_precmd_first})
+ }
+ precmd_functions=(_p9k_instant_prompt_precmd_first $precmd_functions)
+ } && unsetopt prompt_cr prompt_sp'
+ } always {
+ exec {fd}>&-
+ }
+ zf_mv -f $tmp $root_file || return
+ zcompile $root_file || return
+ fi
+
+ local tmp=$prompt_file.tmp.$$
+ zf_mv -f $prompt_file $tmp 2>/dev/null
+ if [[ "$(<$prompt_file)" == *$'\x1e'$_p9k_instant_prompt_sig$'\x1f'* ]] 2>/dev/null; then
+ echo -n >$tmp || return
+ fi
+
+ { print -rn -- entry=$'\x1e'$_p9k_instant_prompt_sig$'\x1f'${(pj:\x1f:)_p9k_t}$'\x1f'$_p9k_instant_prompt >>$tmp } 2>/dev/null || return
+ zf_mv -f $tmp $prompt_file 2>/dev/null || return
+}
+
function _p9k_update_prompt() {
_p9k_refresh_reason=$1
_p9k_set_prompt
@@ -3439,14 +3630,14 @@ _p9k_save_status() {
function _p9k_dump_state() {
is-at-least 5.4 || return # `typeset -g` doesn't roundtrip in zsh prior to 5.4.
local dir=${__p9k_dump_file:h}
- [[ -d $dir ]] || mkdir -pm 0700 $dir || return
+ [[ -d $dir ]] || mkdir -p $dir || return
[[ -w $dir ]] || return
local tmp=$__p9k_dump_file.$$-$EPOCHREALTIME-$RANDOM
local -i fd
sysopen -a -m 600 -o creat,trunc -u fd $tmp || return
{
local include='_POWERLEVEL9K_*|_p9k_*|icons|OS|DEFAULT_COLOR|DEFAULT_COLOR_INVERTED'
- local exclude='_p9k_gitstatus_*|_p9k_cache_stat_meta|_p9k_cache_stat_fprint|_p9k_cache_fprint_key|_p9k_param_sig|_p9k_public_ip|_p9k_prompt|_p9k_prompt_idx|_p9k_dump_pid|_p9k_dump_scheduled|_p9k_line_finished|_p9k_preexec_cmd|_p9k_status|_p9k_pipestatus|_p9k_timer_start|_p9k_region_active|_p9k_keymap|_p9k_zle_state|_p9k_async_pump_*'
+ local exclude='_p9k_gitstatus_*|_p9k_cache_stat_meta|_p9k_cache_stat_fprint|_p9k_cache_fprint_key|_p9k_param_sig|_p9k_public_ip|_p9k_prompt|_p9k_prompt_idx|_p9k_dump_pid|_p9k_state_dump_scheduled|_p9k_line_finished|_p9k_preexec_cmd|_p9k_status|_p9k_pipestatus|_p9k_timer_start|_p9k_region_active|_p9k_keymap|_p9k_zle_state|_p9k_async_pump_*|_p9k_cache_ephemeral'
typeset -g __p9k_cached_param_sig=$_p9k_param_sig
typeset -p __p9k_cached_param_sig >&$fd || return
unset __p9k_cached_param_sig
@@ -3458,9 +3649,7 @@ function _p9k_dump_state() {
exec {fd}>&-
}
zf_mv -f $tmp $__p9k_dump_file || return
- if [[ ${(%):-%#} == % ]]; then
- zcompile $__p9k_dump_file || zf_rm -f $__p9k_dump_file.zwc
- fi
+ zcompile $__p9k_dump_file
}
function _p9k_restore_state() {
@@ -3471,13 +3660,28 @@ function _p9k_restore_state() {
_p9k_state_restored=1
} always {
unset __p9k_cached_param_sig
- if (( !_p9k_state_restored && $+functions[_p9k_preinit] )); then
- unfunction _p9k_preinit
- (( $+functions[gitstatus_stop] )) && gitstatus_stop POWERLEVEL9K
+ if (( !_p9k_state_restored )); then
+ if (( $+functions[_p9k_preinit] )); then
+ unfunction _p9k_preinit
+ (( $+functions[gitstatus_stop] )) && gitstatus_stop POWERLEVEL9K
+ fi
+ local user=${(%):-%n}
+ local root_dir=${__p9k_dump_file:h}
+ zf_rm -f -- $root_dir/p10k-instant-prompt-$user.zsh{,.zwc} ${root_dir}/powerlevel10k-$user/prompt-*(N) 2>/dev/null
fi
}
}
+function _p9k_clear_instant_prompt() {
+ (( $+__p9k_instant_prompt_active )) || return
+ exec 1>&$__p9k_fd_1 2>&$__p9k_fd_2 {__p9k_fd_1}>&- {__p9k_fd_2}>&-
+ unset __p9k_fd_1 __p9k_fd_2 __p9k_instant_prompt_active
+ print -rn -- $terminfo[rc]$terminfo[sgr0]$terminfo[ed]
+ if [[ -s ${TMPDIR:-/tmp}/p10k-instant-prompt-output-$$ ]]; then
+ cat ${TMPDIR:-/tmp}/p10k-instant-prompt-output-$$
+ fi
+}
+
_p9k_precmd_impl() {
emulate -L zsh
setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst}
@@ -3536,24 +3740,46 @@ _p9k_precmd_impl() {
_p9k_keymap=main
_p9k_zle_state=insert
- if ! zle; then
- (( ++_p9k_prompt_idx ))
- fi
+ (( ++_p9k_prompt_idx ))
fi
_p9k_refresh_reason=precmd
_p9k_set_prompt
_p9k_refresh_reason=''
- if ! zle && { (( ! _p9k_dump_pid )) || ! kill -0 $_p9k_dump_pid 2>/dev/null }; then
+ if (( $+__p9k_instant_prompt_active )); then
+ functions -M _p9k_clear_instant_prompt
+ PROMPT='${$((_p9k_clear_instant_prompt()))+}'$PROMPT
+ fi
+
+ _p9k_instant_prompt_sig=$_p9k_pwd:$P9K_SSH:${(%):-%#}
+
+ if (( ! _p9k_dump_pid )) || ! kill -0 $_p9k_dump_pid 2>/dev/null; then
_p9k_dump_pid=0
- if (( _p9k_prompt_idx == 1 && !_p9k_state_restored )); then
- _p9k_dump_state
- _p9k_dump_scheduled=0
- elif (( _p9k_dump_scheduled )); then
- _p9k_dump_state &!
+ if (( _p9k_prompt_idx == 1 )) then
+ _p9k_set_instant_prompt
+ if (( !_p9k_state_restored )); then
+ _p9k_dump_instant_prompt
+ _p9k_dump_state
+ _p9k_state_dump_scheduled=0
+ _p9k_dumped_instant_prompt_sigs[$_p9k_instant_prompt_sig]=1
+ elif [[ "${(j::)__p9k_used_instant_prompt}" != $_p9k_instant_prompt ]]; then
+ _p9k_dump_instant_prompt
+ _p9k_dumped_instant_prompt_sigs[$_p9k_instant_prompt_sig]=1
+ fi
+ elif (( _p9k_state_dump_scheduled || ! $+_p9k_dumped_instant_prompt_sigs[$_p9k_instant_prompt_sig] )); then
+ (
+ if (( ! $+_p9k_dumped_instant_prompt_sigs[$_p9k_instant_prompt_sig] )); then
+ _p9k_set_instant_prompt
+ _p9k_dump_instant_prompt
+ fi
+ if (( _p9k_state_dump_scheduled )); then
+ _p9k_dump_state
+ fi
+ ) &!
_p9k_dump_pid=$!
- _p9k_dump_scheduled=0
+ _p9k_state_dump_scheduled=0
+ _p9k_dumped_instant_prompt_sigs[$_p9k_instant_prompt_sig]=1
fi
fi
}
@@ -3565,6 +3791,7 @@ _p9k_precmd() {
[[ -o sh_glob ]] && __p9k_sh_glob=1 || __p9k_sh_glob=0
unsetopt localoptions
+ (( $+__p9k_instant_prompt_active )) && setopt prompt_sp prompt_cr
prompt_opts=(percent subst)
[[ ! -o prompt_sp ]] || prompt_opts+=sp
[[ ! -o prompt_cr ]] || prompt_opts+=cr
@@ -3765,7 +3992,10 @@ function _p9k_prompt_overflow_bug() {
}
_p9k_init_vars() {
- typeset -gi _p9k_dump_scheduled
+ typeset -gA _p9k_dumped_instant_prompt_sigs
+ typeset -g _p9k_instant_prompt_sig
+ typeset -g _p9k_instant_prompt
+ typeset -gi _p9k_state_dump_scheduled
typeset -gi _p9k_dump_pid
typeset -gi _p9k_prompt_idx
typeset -gi _p9k_state_restored
@@ -3781,6 +4011,7 @@ _p9k_init_vars() {
typeset -g _p9k_cache_stat_fprint
typeset -g _p9k_cache_fprint_key
typeset -gA _p9k_cache
+ typeset -gA _p9k_cache_ephemeral
typeset -ga _p9k_t
typeset -g _p9k_n
typeset -gi _p9k_i
@@ -3865,6 +4096,7 @@ _p9k_init_vars() {
}
_p9k_init_params() {
+ _p9k_declare -i POWERLEVEL9K_INSTANT_PROMPT_COMMAND_LINES 3
_p9k_declare -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS -- context dir vcs
_p9k_declare -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS -- status root_indicator background_jobs history time
_p9k_declare -b POWERLEVEL9K_DISABLE_RPROMPT 0
@@ -4173,9 +4405,8 @@ function _p9k_zle_line_pre_redraw() {
_p9k_reset_prompt
}
-prompt__p9k_internal_nothing() {
- _p9k_prompt+='${_p9k_sss::=}'
-}
+prompt__p9k_internal_nothing() { _p9k_prompt+='${_p9k_sss::=}'; }
+instant_prompt__p9k_internal_nothing() { prompt__p9k_internal_nothing; }
# _p9k_build_gap_post <first|newline>
_p9k_build_gap_post() {
@@ -4335,6 +4566,9 @@ _p9k_all_params_eq() {
}
_p9k_init_prompt() {
+ _p9k_t=($'\n' '')
+ _p9k_prompt_overflow_bug && _p9k_t[2]='%{%G%}'
+
_p9k_init_lines
_p9k_gap_pre='${${:-${_p9k_x::=0}${_p9k_y::=1024}${_p9k_p::=$_p9k_lprompt$_p9k_rprompt}'
@@ -4382,9 +4616,6 @@ _p9k_init_prompt() {
repeat $_POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT _p9k_prompt_newline+=$'\n'
fi
- _p9k_t=($'\n' '')
- _p9k_prompt_overflow_bug && _p9k_t[2]='%{%G%}'
-
if (( _POWERLEVEL9K_SHOW_RULER )); then
_p9k_get_icon '' RULER_CHAR
local ruler_char=$_p9k_ret
@@ -4418,6 +4649,11 @@ _p9k_init_prompt() {
[[ -o transient_rprompt && -n "$_p9k_line_segments_right[1,-2]" ]] ||
( _p9k_segment_in_use time && (( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND )) )
_p9k_reset_on_line_finish=$((!$?))
+
+ _p9k_t+=$_p9k_gap_pre
+ _p9k_gap_pre='${(e)_p9k_t['$#_p9k_t']}'
+ _p9k_t+=$_p9k_prompt_prefix_left
+ _p9k_prompt_prefix_left='${(e)_p9k_t['$#_p9k_t']}'
}
_p9k_init_ssh() {
@@ -4458,7 +4694,7 @@ _p9k_must_init() {
'${GITSTATUS_ENABLE_LOGGING}' '${GITSTATUS_DAEMON}' '${GITSTATUS_NUM_THREADS}'
'${DEFAULT_USER}' '${ZLE_RPROMPT_INDENT}' '${P9K_SSH}' '${__p9k_ksh_arrays}'
'${__p9k_sh_glob}' '${parameters[transient_rprompt]}' '${ITERM_SHELL_INTEGRATION_INSTALLED}'
- 'v8')
+ 'v9')
IFS=$'\2' param_sig="${(e)param_sig}"
[[ $param_sig == $_p9k_param_sig ]] && return 1
[[ -n $_p9k_param_sig ]] && _p9k_deinit
@@ -4755,6 +4991,7 @@ _p9k_deinit() {
typeset -gi __p9k_enabled=0
typeset -gi __p9k_configured=0
+typeset -gri __p9k_instant_prompt_disabled=1
prompt_powerlevel9k_setup() {
emulate -L zsh