retain instant prompt and state dumps when TERM or TERM_PROGRAM change (#1098)

pull/1119/head
Roman Perepelitsa 4 years ago
parent 09be56bb53
commit 7969eb3f18

@ -5758,7 +5758,7 @@ _p9k_set_instant_prompt() {
[[ -n $RPROMPT ]] || unset RPROMPT [[ -n $RPROMPT ]] || unset RPROMPT
} }
typeset -gri __p9k_instant_prompt_version=37 typeset -gri __p9k_instant_prompt_version=38
_p9k_dump_instant_prompt() { _p9k_dump_instant_prompt() {
local user=${(%):-%n} local user=${(%):-%n}
@ -5774,7 +5774,7 @@ _p9k_dump_instant_prompt() {
local -i fd local -i fd
sysopen -a -m 600 -o creat,trunc -u fd -- $tmp || return sysopen -a -m 600 -o creat,trunc -u fd -- $tmp || return
{ {
[[ $TERM_PROGRAM == Hyper ]] && local hyper='==' || local hyper='!=' [[ $TERM == (screen*|tmux*) ]] && local screen='-n' || local screen='-z'
local -a display_v=("${_p9k__display_v[@]}") local -a display_v=("${_p9k__display_v[@]}")
local -i i local -i i
for ((i = 6; i <= $#display_v; i+=2)); do display_v[i]=show; done for ((i = 6; i <= $#display_v; i+=2)); do display_v[i]=show; done
@ -5785,14 +5785,16 @@ _p9k_dump_instant_prompt() {
if [[ -r $gitstatus_dir/install.info ]]; then if [[ -r $gitstatus_dir/install.info ]]; then
IFS= read -r gitstatus_header <$gitstatus_dir/install.info || return IFS= read -r gitstatus_header <$gitstatus_dir/install.info || return
fi fi
>&$fd print -r -- '[[ -t 0 && -t 1 && -t 2 && -o interactive && -o zle && -o no_xtrace ]] &&
! (( ${+__p9k_instant_prompt_disabled} || ZSH_SUBSHELL || ${+ZSH_SCRIPT} || ${+ZSH_EXECUTION_STRING} )) || return 0'
>&$fd print -r -- "() { >&$fd print -r -- "() {
$__p9k_intro_no_locale $__p9k_intro_no_locale
(( ! \$+__p9k_instant_prompt_disabled )) || return typeset -gi __p9k_instant_prompt_disabled=1
typeset -gi __p9k_instant_prompt_disabled=1 __p9k_instant_prompt_sourced=$__p9k_instant_prompt_version
[[ \$ZSH_VERSION == ${(q)ZSH_VERSION} && \$ZSH_PATCHLEVEL == ${(q)ZSH_PATCHLEVEL} && [[ \$ZSH_VERSION == ${(q)ZSH_VERSION} && \$ZSH_PATCHLEVEL == ${(q)ZSH_PATCHLEVEL} &&
\$TERM_PROGRAM $hyper 'Hyper' && \$+VTE_VERSION == $+VTE_VERSION && \$TERM == ${(q)TERM} && $screen \${(M)TERM:#(screen*|tmux*)} &&
\${#\${(M)VTE_VERSION:#(<1-4602>|4801)}} == ${#${(M)VTE_VERSION:#(<1-4602>|4801)}} &&
\$POWERLEVEL9K_DISABLE_INSTANT_PROMPT != 'true' && \$POWERLEVEL9K_DISABLE_INSTANT_PROMPT != 'true' &&
\$POWERLEVEL9K_INSTANT_PROMPT != 'off' ]] || { __p9k_instant_prompt_sourced=0; return 1; } \$POWERLEVEL9K_INSTANT_PROMPT != 'off' ]] || return
typeset -g __p9k_instant_prompt_param_sig=${(q+)_p9k__param_sig} typeset -g __p9k_instant_prompt_param_sig=${(q+)_p9k__param_sig}
local gitstatus_dir=${(q)gitstatus_dir} local gitstatus_dir=${(q)gitstatus_dir}
local gitstatus_header=${(q)gitstatus_header} local gitstatus_header=${(q)gitstatus_header}
@ -5808,12 +5810,7 @@ _p9k_dump_instant_prompt() {
if [[ -r $gitstatus_dir/install.info ]]; then if [[ -r $gitstatus_dir/install.info ]]; then
IFS= read -r real_gitstatus_header <$gitstatus_dir/install.info || real_gitstatus_header=borked IFS= read -r real_gitstatus_header <$gitstatus_dir/install.info || real_gitstatus_header=borked
fi fi
if [[ $real_gitstatus_header != $gitstatus_header ]]; then [[ $real_gitstatus_header == $gitstatus_header ]] || return
__p9k_instant_prompt_sourced=0
return 1
fi
[[ $ZSH_SUBSHELL == 0 && -z $ZSH_SCRIPT && -z $ZSH_EXECUTION_STRING &&
-t 0 && -t 1 && -t 2 && -o interactive && -o zle && -o no_xtrace ]] || return
zmodload zsh/langinfo zsh/terminfo zsh/system || return zmodload zsh/langinfo zsh/terminfo zsh/system || return
if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]]; then if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]]; then
local loc_cmd=$commands[locale] local loc_cmd=$commands[locale]
@ -5833,9 +5830,16 @@ _p9k_dump_instant_prompt() {
local prompt_file=$prompt_dir/prompt-${#pwd} local prompt_file=$prompt_dir/prompt-${#pwd}
local key=$pwd:$ssh:${(%):-%#} local key=$pwd:$ssh:${(%):-%#}
local content local content
if [[ ! -e $prompt_file ]]; then
typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version'
return 1
fi
{ content="$(<$prompt_file)" } 2>/dev/null || return { content="$(<$prompt_file)" } 2>/dev/null || return
local tail=${content##*$rs$key$us} local tail=${content##*$rs$key$us}
[[ ${#tail} != ${#content} ]] || return if (( ${#tail} == ${#content} )); then
typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version'
return 1
fi
local P9K_PROMPT=instant local P9K_PROMPT=instant
if [[ -z $P9K_TTY || $P9K_TTY == old && -n ${_P9K_TTY:#$TTY} ]]; then' if [[ -z $P9K_TTY || $P9K_TTY == old && -n ${_P9K_TTY:#$TTY} ]]; then'
if (( _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS < 0 )); then if (( _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS < 0 )); then
@ -5962,37 +5966,36 @@ _p9k_dump_instant_prompt() {
fi fi
>&$fd print -r -- ' >&$fd print -r -- '
trap "unset -m _p9k__\*; unfunction p10k" EXIT trap "unset -m _p9k__\*; unfunction p10k" EXIT
local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}")' local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}")
if [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]]; then if [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && (( $+commands[stty] )); then
if [[ $TERM_PROGRAM == Hyper ]]; then if [[ $TERM_PROGRAM == Hyper ]]; then
local bad_lines=40 bad_columns=100 local bad_lines=40 bad_columns=100
else else
local bad_lines=24 bad_columns=80 local bad_lines=24 bad_columns=80
fi fi
>&$fd print -r -- ' if (( LINES == bad_lines && COLUMNS == bad_columns )); then
if (( LINES == '$bad_lines' && COLUMNS == '$bad_columns' )); then zmodload -F zsh/stat b:zstat || return
zmodload -F zsh/stat b:zstat || return zmodload zsh/datetime || return
zmodload zsh/datetime || return local -a tty_ctime
local -a tty_ctime if ! zstat -A tty_ctime +ctime -- $TTY 2>/dev/null || (( tty_ctime[1] + 2 > EPOCHREALTIME )); then
if ! zstat -A tty_ctime +ctime -- $TTY 2>/dev/null || (( tty_ctime[1] + 2 > EPOCHREALTIME )); then local -F deadline=$((EPOCHREALTIME+0.025))
local -F deadline=$((EPOCHREALTIME+0.025)) local tty_size
local tty_size while true; do
while true; do if (( EPOCHREALTIME > deadline )) || ! tty_size="$(command stty size 2>/dev/null)" || [[ $tty_size != <->" "<-> ]]; then
if (( EPOCHREALTIME > deadline )) || ! tty_size="$(/bin/stty size 2>/dev/null)" || [[ $tty_size != <->" "<-> ]]; then (( $+_p9k__ruler_i )) || local -i _p9k__ruler_i=1
(( $+_p9k__ruler_i )) || local -i _p9k__ruler_i=1 local _p9k__g= _p9k__'$#_p9k_line_segments_right'r= _p9k__'$#_p9k_line_segments_right'r_frame=
local _p9k__g= _p9k__'$#_p9k_line_segments_right'r= _p9k__'$#_p9k_line_segments_right'r_frame= break
break fi
fi if [[ $tty_size != "$bad_lines $bad_columns" ]]; then
if [[ $tty_size != "'$bad_lines' '$bad_columns'" ]]; then local lines_columns=(${=tty_size})
local lines_columns=(${=tty_size}) local LINES=$lines_columns[1]
local LINES=$lines_columns[1] local COLUMNS=$lines_columns[2]
local COLUMNS=$lines_columns[2] break
break fi
fi done
done fi
fi fi
fi' fi'
fi
(( __p9k_ksh_arrays )) && >&$fd print -r -- ' setopt ksh_arrays' (( __p9k_ksh_arrays )) && >&$fd print -r -- ' setopt ksh_arrays'
(( __p9k_sh_glob )) && >&$fd print -r -- ' setopt sh_glob' (( __p9k_sh_glob )) && >&$fd print -r -- ' setopt sh_glob'
>&$fd print -r -- ' typeset -ga __p9k_used_instant_prompt=("${(@e)_p9k_t[-3,-1]}")' >&$fd print -r -- ' typeset -ga __p9k_used_instant_prompt=("${(@e)_p9k_t[-3,-1]}")'
@ -6017,15 +6020,13 @@ _p9k_dump_instant_prompt() {
fi fi
_p9k__ret=$x _p9k__ret=$x
} }
local out' local out
[[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && >&$fd print -r -- ' if (( ! $+_p9k__g )); then' if [[ $+VTE_VERSION == 0 && $TERM_PROGRAM != Hyper ]] || (( ! $+_p9k__g )); then
>&$fd print -r -- ' local mark=${(e)PROMPT_EOL_MARK}
local mark=${(e)PROMPT_EOL_MARK} [[ $mark == "%B%S%#%s%b" ]] && _p9k__ret=1 || _p9k_prompt_length $mark
[[ $mark == "%B%S%#%s%b" ]] && _p9k__ret=1 || _p9k_prompt_length $mark local -i fill=$((COLUMNS > _p9k__ret ? COLUMNS - _p9k__ret : 0))
local -i fill=$((COLUMNS > _p9k__ret ? COLUMNS - _p9k__ret : 0)) out+="${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}"
out+="${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}"' fi
[[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && >&$fd print -r -- ' fi'
>&$fd print -r -- '
out+="${(pl.$height..$lf.)}$esc${height}A$terminfo[sc]" out+="${(pl.$height..$lf.)}$esc${height}A$terminfo[sc]"
out+=${(%):-"$__p9k_used_instant_prompt[1]$__p9k_used_instant_prompt[2]"} out+=${(%):-"$__p9k_used_instant_prompt[1]$__p9k_used_instant_prompt[2]"}
if [[ -n $__p9k_used_instant_prompt[3] ]]; then if [[ -n $__p9k_used_instant_prompt[3] ]]; then
@ -6094,7 +6095,8 @@ _p9k_dump_instant_prompt() {
zshexit_functions=(_p9k_instant_prompt_cleanup $zshexit_functions) zshexit_functions=(_p9k_instant_prompt_cleanup $zshexit_functions)
precmd_functions=(_p9k_instant_prompt_precmd_first $precmd_functions) precmd_functions=(_p9k_instant_prompt_precmd_first $precmd_functions)
DISABLE_UPDATE_PROMPT=true DISABLE_UPDATE_PROMPT=true
} && unsetopt prompt_cr prompt_sp || true' } && unsetopt prompt_cr prompt_sp && typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version' ||
typeset -gi __p9k_instant_prompt_sourced=${__p9k_instant_prompt_sourced:-0}'
} always { } always {
exec {fd}>&- exec {fd}>&-
} }
@ -7936,11 +7938,11 @@ _p9k_must_init() {
_p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1' _p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1'
_p9k__param_pat+=$'$GITSTATUS_CACHE_DIR\1$GITSTATUS_AUTO_INSTALL\1${ZLE_RPROMPT_INDENT:-1}\1' _p9k__param_pat+=$'$GITSTATUS_CACHE_DIR\1$GITSTATUS_AUTO_INSTALL\1${ZLE_RPROMPT_INDENT:-1}\1'
_p9k__param_pat+=$'$__p9k_sh_glob\1$__p9k_ksh_arrays\1$ITERM_SHELL_INTEGRATION_INSTALLED\1' _p9k__param_pat+=$'$__p9k_sh_glob\1$__p9k_ksh_arrays\1$ITERM_SHELL_INTEGRATION_INSTALLED\1'
_p9k__param_pat+=$'${PROMPT_EOL_MARK-%B%S%#%s%b}\1$commands[locale]\1$langinfo[CODESET]\1' _p9k__param_pat+=$'${PROMPT_EOL_MARK-%B%S%#%s%b}\1$+commands[locale]\1$langinfo[CODESET]\1'
_p9k__param_pat+=$'$VTE_VERSION\1$TERM_PROGRAM\1$DEFAULT_USER\1$P9K_SSH\1$commands[uname]\1' _p9k__param_pat+=$'${(M)VTE_VERSION:#(<1-4602>|4801)}\1$DEFAULT_USER\1$P9K_SSH\1$+commands[uname]\1'
_p9k__param_pat+=$'$__p9k_root_dir\1$functions[p10k-on-init]\1$functions[p10k-on-pre-prompt]\1' _p9k__param_pat+=$'$__p9k_root_dir\1$functions[p10k-on-init]\1$functions[p10k-on-pre-prompt]\1'
_p9k__param_pat+=$'$functions[p10k-on-post-widget]\1$functions[p10k-on-post-prompt]\1' _p9k__param_pat+=$'$functions[p10k-on-post-widget]\1$functions[p10k-on-post-prompt]\1'
_p9k__param_pat+=$'$+commands[git]\1$terminfo[colors]\1$TERM' _p9k__param_pat+=$'$+commands[git]\1$terminfo[colors]'
local MATCH local MATCH
IFS=$'\1' _p9k__param_pat+="${(@)${(@o)parameters[(I)POWERLEVEL9K_*]}:/(#m)*/\${${(q)MATCH}-$IFS\}}" IFS=$'\1' _p9k__param_pat+="${(@)${(@o)parameters[(I)POWERLEVEL9K_*]}:/(#m)*/\${${(q)MATCH}-$IFS\}}"
IFS=$'\2' _p9k__param_sig="${(e)_p9k__param_pat}" IFS=$'\2' _p9k__param_sig="${(e)_p9k__param_pat}"
@ -8357,6 +8359,11 @@ _p9k_init() {
_p9k_dumped_instant_prompt_sigs=() _p9k_dumped_instant_prompt_sigs=()
fi fi
if (( $+__p9k_instant_prompt_sourced && __p9k_instant_prompt_sourced != __p9k_instant_prompt_version )); then
_p9k_delete_instant_prompt
_p9k_dumped_instant_prompt_sigs=()
fi
if (( $+__p9k_instant_prompt_erased )); then if (( $+__p9k_instant_prompt_erased )); then
unset __p9k_instant_prompt_erased unset __p9k_instant_prompt_erased
{ {
@ -8832,10 +8839,5 @@ if [[ $__p9k_dump_file != $__p9k_instant_prompt_dump_file && -n $__p9k_instant_p
zf_rm -f -- $__p9k_instant_prompt_dump_file{,.zwc} 2>/dev/null zf_rm -f -- $__p9k_instant_prompt_dump_file{,.zwc} 2>/dev/null
fi fi
if [[ $+__p9k_instant_prompt_sourced == 1 && $__p9k_instant_prompt_sourced != $__p9k_instant_prompt_version ]]; then
_p9k_delete_instant_prompt
zf_rm -f -- $__p9k_dump_file{,.zwc} 2>/dev/null
fi
_p9k_init_ssh _p9k_init_ssh
prompt_powerlevel9k_setup prompt_powerlevel9k_setup

Loading…
Cancel
Save