take advantage of async gitstatus start to make p10k startup faster

pull/243/head
romkatv 5 years ago
parent 9d0c49dc58
commit d435235c29

@ -3359,36 +3359,42 @@ _p9k_save_status() {
function _p9k_dump_state() { function _p9k_dump_state() {
is-at-least 5.3 || return is-at-least 5.3 || return
local dir=${_p9k_state_file:h} local dir=${__p9k_dump_file:h}
[[ -d $dir ]] || mkdir -pm 0700 $dir || return [[ -d $dir ]] || mkdir -pm 0700 $dir || return
[[ -w $dir && -z $dir(#qNR) ]] || return [[ -w $dir && -z $dir(#qNR) ]] || return
local tmp=$_p9k_state_file.$$-$EPOCHREALTIME-$RANDOM local tmp=$__p9k_dump_file.$$-$EPOCHREALTIME-$RANDOM
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
{ {
local include='_POWERLEVEL9K_*|_p9k_*|icons|OS|DEFAULT_COLOR|DEFAULT_COLOR_INVERTED' local include='_POWERLEVEL9K_*|_p9k_*|icons|OS|DEFAULT_COLOR|DEFAULT_COLOR_INVERTED'
local exclude='_p9k_gitstatus_*|_p9k_param_sig|_p9k_public_ip|_p9k_prompt|_p9k_prompt_idx' local exclude='_p9k_gitstatus_*|_p9k_param_sig|_p9k_public_ip|_p9k_prompt|_p9k_prompt_idx'
local _p9k_cached_param_sig=$_p9k_param_sig typeset -g __p9k_cached_param_sig=$_p9k_param_sig
typeset -p _p9k_cached_param_sig >&$fd || return typeset -p __p9k_cached_param_sig >&$fd || return
unset __p9k_cached_param_sig
(( $+functions[_p9k_preinit] )) && functions _p9k_preinit >&$fd || return
print -r -- '_p9k_restore_state_impl() {' >&$fd || return print -r -- '_p9k_restore_state_impl() {' >&$fd || return
typeset -pm "($include)~($exclude)" >&$fd || return typeset -pm "($include)~($exclude)" >&$fd || return
print -r -- '}' >&$fd || return print -r -- '}' >&$fd || return
} always { } always {
exec {fd}>&- exec {fd}>&-
} }
zf_mv -f $tmp $_p9k_state_file zf_mv -f $tmp $__p9k_dump_file || return
zcompile $_p9k_state_file zcompile $__p9k_dump_file || zf_rm -f $__p9k_dump_file.zwc
} }
function _p9k_restore_state() { function _p9k_restore_state() {
[[ -z $_p9k_state_file(.zwc|)(#qNW) ]] || return {
unset _p9k_cached_param_sig [[ $__p9k_cached_param_sig == $_p9k_param_sig ]] || return
(( $+functions[_p9k_restore_state_impl] )) && unfunction _p9k_restore_state_impl
source $_p9k_state_file 2>/dev/null || return
[[ $_p9k_cached_param_sig == $_p9k_param_sig ]] || return
(( $+functions[_p9k_restore_state_impl] )) || return (( $+functions[_p9k_restore_state_impl] )) || return
_p9k_restore_state_impl _p9k_restore_state_impl
_p9k_state_restored=1 _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
fi
}
} }
_p9k_precmd_impl() { _p9k_precmd_impl() {
@ -4515,14 +4521,16 @@ function _p9k_init_cacheable() {
fi fi
} }
_p9k_init() { _p9k_init_vcs() {
_p9k_init_vars _p9k_segment_in_use vcs || return
typeset -g _p9k_state_file=${XDG_CACHE_HOME:-~/.cache}/p10k-state-${(%):-%n}.zsh
_p9k_restore_state || _p9k_init_cacheable
if _p9k_segment_in_use vcs; then
_p9k_vcs_info_init _p9k_vcs_info_init
if [[ $_POWERLEVEL9K_DISABLE_GITSTATUS == 0 && -n $_POWERLEVEL9K_VCS_BACKENDS[(r)git] ]]; then if (( $+functions[_p9k_preinit] )); then
(( $+parameters[GITSTATUS_DAEMON_PID_POWERLEVEL9K] )) && gitstatus_start POWERLEVEL9K || _p9k_gitstatus_disabled=1
return
fi
(( _POWERLEVEL9K_DISABLE_GITSTATUS )) && return
(( $_POWERLEVEL9K_VCS_BACKENDS[(I)git] )) || return
local gitstatus_dir=${_POWERLEVEL9K_GITSTATUS_DIR:-${__p9k_root_dir}/gitstatus} local gitstatus_dir=${_POWERLEVEL9K_GITSTATUS_DIR:-${__p9k_root_dir}/gitstatus}
if [[ -z $GITSTATUS_DAEMON && $_p9k_uname == i686 && -z $gitstatus_dir/bin/*-i686(-static|)(#qN) ]]; then if [[ -z $GITSTATUS_DAEMON && $_p9k_uname == i686 && -z $gitstatus_dir/bin/*-i686(-static|)(#qN) ]]; then
_p9k_gitstatus_disabled=1 _p9k_gitstatus_disabled=1
@ -4556,33 +4564,46 @@ _p9k_init() {
>&2 echo -E - "" >&2 echo -E - ""
>&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
>&2 echo -E - "${(%):- * Git prompt will be %Bfast%b.}" >&2 echo -E - "${(%):- * Git prompt will be %Bfast%b.}"
else return
local -i daemon threads fi
if (( ! $+GITSTATUS_DAEMON )); then
local os=$_p9k_uname local daemon=${GITSTATUS_DAEMON}
[[ $_p9k_uname == Linux && _p9k_uname_o == Android ]] && os=Android if [[ -z $daemon ]]; then
typeset -g GITSTATUS_DAEMON=$gitstatus_dir/bin/gitstatusd-${os:l}-${_p9k_uname_m:l} daemon=$gitstatus_dir/bin/gitstatusd-
daemon=1 [[ _p9k_uname_o == Android ]] && daemon+=android || daemon+=${_p9k_uname:l}
fi daemon+=-${_p9k_uname_m:l}
if (( ! $+GITSTATUS_NUM_THREADS )); then fi
typeset -gi GITSTATUS_NUM_THREADS=$(( _p9k_num_cpus * 2 )) local -i threads=${GITSTATUS_NUM_THREADS:-0}
(( GITSTATUS_NUM_THREADS > 0 )) || GITSTATUS_NUM_THREADS=8 if (( threads <= 0 )); then
(( GITSTATUS_NUM_THREADS <= 32 )) || GITSTATUS_NUM_THREADS=32 threads=$(( _p9k_num_cpus * 2 ))
threads=1 (( threads > 0 )) || threads=8
fi (( threads <= 32 )) || threads=32
source $gitstatus_dir/gitstatus.plugin.zsh fi
gitstatus_start \ eval "function _p9k_preinit() {
source ${(q)gitstatus_dir}/gitstatus.plugin.zsh
GITSTATUS_DAEMON=${(q)daemon} GITSTATUS_NUM_THREADS=$threads \
GITSTATUS_LOG_LEVEL=${(q)GITSTATUS_LOG_LEVEL} \
GITSTATUS_ENABLE_LOGGING=${(q)GITSTATUS_ENABLE_LOGGING} gitstatus_start \
-s $_POWERLEVEL9K_VCS_STAGED_MAX_NUM \
-u $_POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM \
-d $_POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM \
-c $_POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM \
-m $_POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY \
-a POWERLEVEL9K
}"
source ${gitstatus_dir}/gitstatus.plugin.zsh
GITSTATUS_DAEMON=$daemon GITSTATUS_NUM_THREADS=$threads gitstatus_start \
-s $_POWERLEVEL9K_VCS_STAGED_MAX_NUM \ -s $_POWERLEVEL9K_VCS_STAGED_MAX_NUM \
-u $_POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM \ -u $_POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM \
-d $_POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM \ -d $_POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM \
-c $_POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM \ -c $_POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM \
-m $_POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY \ -m $_POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY \
POWERLEVEL9K || _p9k_gitstatus_disabled=1 POWERLEVEL9K || _p9k_gitstatus_disabled=1
(( daemon )) && unset GITSTATUS_DAEMON }
(( threads )) && unset GITSTATUS_NUM_THREADS
fi _p9k_init() {
fi _p9k_init_vars
fi _p9k_restore_state || _p9k_init_cacheable
if _p9k_segment_in_use todo; then if _p9k_segment_in_use todo; then
local todo=$commands[todo.sh] local todo=$commands[todo.sh]
@ -4622,6 +4643,7 @@ _p9k_init() {
fi fi
_p9k_init_async_pump _p9k_init_async_pump
_p9k_init_vcs
} }
_p9k_deinit() { _p9k_deinit() {
@ -4824,7 +4846,7 @@ zmodload zsh/parameter
zmodload zsh/system zmodload zsh/system
zmodload -F zsh/stat b:zstat zmodload -F zsh/stat b:zstat
zmodload -F zsh/net/socket b:zsocket zmodload -F zsh/net/socket b:zsocket
zmodload -F zsh/files b:zf_mv zmodload -F zsh/files b:zf_mv b:zf_rm
_p9k_init_ssh _p9k_init_ssh
prompt_powerlevel9k_setup prompt_powerlevel9k_setup

@ -17,7 +17,8 @@
[[ ! -o 'no_brace_expand' ]] || _p9k_src_opts+=('no_brace_expand') [[ ! -o 'no_brace_expand' ]] || _p9k_src_opts+=('no_brace_expand')
'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand' 'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand'
typeset -g __p9k_root_dir="${POWERLEVEL9K_INSTALLATION_DIR:-${${(%):-%x}:A:h}}" typeset -g __p9k_root_dir=${POWERLEVEL9K_INSTALLATION_DIR:-${${(%):-%x}:A:h}}
typeset -g __p9k_dump_file=${XDG_CACHE_HOME:-~/.cache}/p10k-dump-${(%):-%n}.zsh
() { () {
emulate -L zsh emulate -L zsh
@ -27,10 +28,15 @@ typeset -g __p9k_root_dir="${POWERLEVEL9K_INSTALLATION_DIR:-${${(%):-%x}:A:h}}"
return return
fi fi
typeset -gr __p9k_sourced=1 typeset -gr __p9k_sourced=1
if [[ -w $__p9k_root_dir && -w $__p9k_root_dir/internal && -w $__p9k_root_dir/gitstatus && ${(%):-%#} == % ]]; then
local f local f
for f in $__p9k_root_dir/{powerlevel9k.zsh-theme,powerlevel10k.zsh-theme,internal/p10k.zsh,internal/icons.zsh,internal/configure.zsh,gitstatus/gitstatus.plugin.zsh}; do for f in $__p9k_root_dir/{powerlevel9k.zsh-theme,powerlevel10k.zsh-theme,internal/p10k.zsh,internal/icons.zsh,internal/configure.zsh,gitstatus/gitstatus.plugin.zsh}; do
[[ $f.zwc -nt $f ]] || zcompile $f [[ $f.zwc -nt $f ]] || zcompile $f
done done
fi
if [[ -z $__p9k_dump_file(.zwc|)(#qNW) ]] && source $__p9k_dump_file 2>/dev/null && (( $+functions[_p9k_preinit] )); then
_p9k_preinit
fi
source $__p9k_root_dir/internal/p10k.zsh || true source $__p9k_root_dir/internal/p10k.zsh || true
} }

Loading…
Cancel
Save