aboutsummaryrefslogtreecommitdiff
path: root/internal/p10k.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'internal/p10k.zsh')
-rw-r--r--internal/p10k.zsh180
1 files changed, 125 insertions, 55 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index d6707fbf..51f376fc 100644
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -3687,9 +3687,16 @@ function _p9k_vcs_resume() {
fi
fi
- _p9k__refresh_reason=gitstatus
- _p9k_set_prompt
- _p9k__refresh_reason=''
+ if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
+ local _p9k__prompt _p9k__prompt_side=$_p9k_vcs_side
+ local -i _p9k__has_upglob _p9k__segment_index=_p9k_vcs_index
+ _p9k_vcs_render
+ typeset -g _p9k__vcs=$_p9k__prompt
+ else
+ _p9k__refresh_reason=gitstatus
+ _p9k_set_prompt
+ _p9k__refresh_reason=''
+ fi
_p9k_reset_prompt
}
@@ -3724,6 +3731,16 @@ function _p9k_vcs_gitstatus() {
fi
(( _p9k__prompt_idx == 1 )) && timeout=0
_p9k__git_dir=$GIT_DIR
+ if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
+ if ! gitstatus_query -d $_p9k__cwd_a -t 0 -c '_p9k_vcs_resume 1' POWERLEVEL9K; then
+ unset VCS_STATUS_RESULT
+ return 1
+ fi
+ _p9k__gitstatus_next_dir=''
+ _p9k__gitstatus_start_time=$EPOCHREALTIME
+ typeset -g _p9k__vcs=
+ return 0
+ fi
if ! gitstatus_query -d $_p9k__cwd_a -t $timeout -c '_p9k_vcs_resume 1' POWERLEVEL9K; then
unset VCS_STATUS_RESULT
return 1
@@ -3743,8 +3760,13 @@ function _p9k_vcs_gitstatus() {
# Segment to show VCS information
prompt_vcs() {
+ if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
+ _p9k__prompt+='${(e)_p9k__vcs}'
+ return
+ fi
+
local -a backends=($_POWERLEVEL9K_VCS_BACKENDS)
- if (( ${backends[(I)git]} && !_p9k__gitstatus_disabled )) && _p9k_vcs_gitstatus; then
+ if (( ${backends[(I)git]} && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )) && _p9k_vcs_gitstatus; then
_p9k_vcs_render && return
backends=(${backends:#git})
fi
@@ -5079,6 +5101,8 @@ function _p9k_set_prompt() {
[[ $1 == instant_ ]] || PROMPT+='${$((_p9k_on_expand()))+}'
PROMPT+=$_p9k_prompt_prefix_left
+ local -i _p9k__has_upglob
+
local -i left_idx=1 right_idx=1 num_lines=$#_p9k_line_segments_left
for _p9k__line_index in {1..$num_lines}; do
local right=
@@ -6017,6 +6041,14 @@ _p9k_precmd_impl() {
_p9k_fetch_cwd
+ _p9k__refresh_reason=precmd
+ __p9k_reset_state=1
+
+ if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
+ unset _p9k__vcs
+ _p9k_vcs_gitstatus
+ fi
+
local f_compute
for f_compute in "${_p9k__async_segments_compute[@]}"; do
_p9k_worker_invoke ${f_compute%% *} ${(e)f_compute}
@@ -6024,8 +6056,8 @@ _p9k_precmd_impl() {
_p9k__expanded=0
- _p9k__refresh_reason=precmd
_p9k_set_prompt
+
_p9k__refresh_reason=''
if [[ $precmd_functions[1] != _p9k_do_nothing && $precmd_functions[(I)_p9k_do_nothing] != 0 ]]; then
@@ -6041,7 +6073,17 @@ _p9k_precmd_impl() {
preexec_functions=(${(@)preexec_functions:#_p9k_preexec2} _p9k_preexec2)
fi
- __p9k_reset_state=1
+ if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
+ # TODO: use better timeout
+ gitstatus_process_results -t $_POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS POWERLEVEL9K
+ if (( ! $+_p9k__vcs )); then
+ local _p9k__prompt _p9k__prompt_side=$_p9k_vcs_side
+ local -i _p9k__has_upglob _p9k__segment_index=_p9k_vcs_index
+ _p9k_vcs_render
+ typeset -g _p9k__vcs=$_p9k__prompt
+ fi
+ fi
+
_p9k_worker_receive
__p9k_reset_state=0
}
@@ -6105,6 +6147,9 @@ typeset -g _p9k__param_pat
typeset -g _p9k__param_sig
_p9k_init_vars() {
+ typeset -gi _p9k_vcs_index
+ typeset -g _p9k_vcs_side
+
typeset -ga _p9k_taskwarrior_meta_files
typeset -ga _p9k_taskwarrior_meta_non_files
typeset -g _p9k_taskwarrior_meta_sig
@@ -6223,7 +6268,6 @@ _p9k_init_vars() {
typeset -gA _p9k_git_slow
# git workdir => the last state we've seen for it
typeset -gA _p9k__gitstatus_last
- typeset -gi _p9k__gitstatus_disabled
typeset -gF _p9k__gitstatus_start_time
typeset -g _p9k__prompt
typeset -g _p9k__rprompt
@@ -7172,7 +7216,7 @@ _p9k_must_init() {
[[ $sig == $_p9k__param_sig ]] && return 1
_p9k_deinit
fi
- _p9k__param_pat=$'v56\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1'
+ _p9k__param_pat=$'v57\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'
@@ -7362,27 +7406,72 @@ function _p9k_init_cacheable() {
done
fi
fi
+
+ if [[ $#_POWERLEVEL9K_VCS_BACKENDS == 1 && $_POWERLEVEL9K_VCS_BACKENDS[1] == git ]]; then
+ local elem line
+ local -i i=0
+ for line in $_p9k_line_segments_left; do
+ for elem in ${${(0)line}%_joined}; do
+ (( ++i ))
+ if [[ $elem == vcs ]]; then
+ if (( _p9k_vcs_index )); then
+ _p9k_vcs_index=-1
+ else
+ _p9k_vcs_index=i
+ _p9k_vcs_side=left
+ fi
+ fi
+ done
+ done
+ i=0
+ for line in $_p9k_line_segments_right; do
+ for elem in ${${(0)line}%_joined}; do
+ (( ++i ))
+ if [[ $elem == vcs ]]; then
+ if (( _p9k_vcs_index )); then
+ _p9k_vcs_index=-1
+ else
+ _p9k_vcs_index=i
+ _p9k_vcs_side=right
+ fi
+ fi
+ done
+ done
+ if (( _p9k_vcs_index > 0 )); then
+ local state
+ for state in ${(k)__p9k_vcs_states}; do
+ _p9k_param prompt_vcs_$state CONTENT_EXPANSION x
+ if [[ -z $_p9k__ret ]]; then
+ _p9k_vcs_index=-1
+ break
+ fi
+ done
+ fi
+ if (( _p9k_vcs_index == -1 )); then
+ _p9k_vcs_index=0
+ _p9k_vcs_side=
+ fi
+ fi
}
_p9k_init_vcs() {
_p9k_segment_in_use vcs || return
_p9k_vcs_info_init
if (( $+functions[_p9k_preinit] )); then
- (( $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )) && gitstatus_start POWERLEVEL9K || _p9k__gitstatus_disabled=1
- return 0
- fi
- if (( _POWERLEVEL9K_DISABLE_GITSTATUS )); then
- _p9k__gitstatus_disabled=1
+ (( $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )) && gitstatus_start POWERLEVEL9K
return 0
fi
+ (( _POWERLEVEL9K_DISABLE_GITSTATUS )) && return
(( $_POWERLEVEL9K_VCS_BACKENDS[(I)git] )) || return
local gitstatus_dir=${_POWERLEVEL9K_GITSTATUS_DIR:-${__p9k_root_dir}/gitstatus}
- if [[ -z $GITSTATUS_DAEMON && $_p9k_uname_m == (i686|arm7l) && -z $gitstatus_dir/bin/*-$_p9k_uname_m(-static|)(#qN) ]]; then
- _p9k__gitstatus_disabled=1
+
+ local id=${(L)${${(M)_p9k_uname_o:#Android}:-$_p9k_uname}}-${(L)_p9k_uname_m}
+ if [[ -z $GITSTATUS_DAEMON && $id == (android-arm7l|*-i686) &&
+ -z $gitstatus_dir/bin/(usrbin|bin)/*-$id(|-static)(#qN) ]]; then
>&2 echo -E - "${(%):-[%1FERROR%f]: %BPowerlevel10k%b is unable to use %Bgitstatus%b. Git prompt will be slow.}"
>&2 echo -E - ""
- >&2 echo -E - "${(%):-Reason: There is no %Bgitstatusd%b binary for $_p9k_uname_m (32-bit architecture).}"
+ >&2 echo -E - "${(%):-Reason: There is no %Bgitstatusd%b binary for %B${id//\%/%%}%b (32-bit).}"
>&2 echo -E - ""
>&2 echo -E - "${(%):-You can:}"
>&2 echo -E - ""
@@ -7413,50 +7502,31 @@ _p9k_init_vcs() {
return 0
fi
- local daemon=${GITSTATUS_DAEMON}
- if [[ -z $daemon ]]; then
- daemon=$gitstatus_dir/bin/gitstatusd-
- if [[ $_p9k_uname_o == Android ]]; then
- daemon+=android
- elif [[ $_p9k_uname == (#i)(mingw|msys)* ]]; then
- daemon+=msys_nt-10.0
- elif [[ $_p9k_uname == (#i)cygwin_nt* ]]; then
- daemon+=cygwin_nt-10.0
- else
- daemon+=${_p9k_uname:l}
- fi
- daemon+=-${_p9k_uname_m:l}
- fi
- local -i threads=${GITSTATUS_NUM_THREADS:-0}
- if (( threads <= 0 )); then
- threads=$(( _p9k_num_cpus * 2 ))
- (( threads > 0 )) || threads=8
- (( threads <= 32 )) || threads=32
- fi
typeset -g _p9k_preinit="function _p9k_preinit() {
[[ \$ZSH_VERSION == ${(q)ZSH_VERSION} ]] || return
[[ -r ${(q)gitstatus_dir}/gitstatus.plugin.zsh ]] || return
source ${(q)gitstatus_dir}/gitstatus.plugin.zsh || return
- 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 \
- ${${_POWERLEVEL9K_VCS_RECURSE_UNTRACKED_DIRS:#0}:+-e} \
- -a POWERLEVEL9K
+ GITSTATUS_DAEMON=${(q)GITSTATUS_DAEMON} \
+ GITSTATUS_NUM_THREADS=${(q)GITSTATUS_NUM_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 \
+ ${${_POWERLEVEL9K_VCS_RECURSE_UNTRACKED_DIRS:#0}:+-e} \
+ -a POWERLEVEL9K
}"
- source ${gitstatus_dir}/gitstatus.plugin.zsh
- GITSTATUS_DAEMON=$daemon GITSTATUS_NUM_THREADS=$threads 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 \
- ${${_POWERLEVEL9K_VCS_RECURSE_UNTRACKED_DIRS:#0}:+-e} \
- POWERLEVEL9K || _p9k__gitstatus_disabled=1
+ source $gitstatus_dir/gitstatus.plugin.zsh && 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 \
+ ${${_POWERLEVEL9K_VCS_RECURSE_UNTRACKED_DIRS:#0}:+-e} \
+ POWERLEVEL9K
}
_p9k_init() {