1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-16 17:50:09 +00:00

speed up truncate_to_unique

This commit is contained in:
romkatv 2019-07-19 14:19:24 +02:00
parent b7a8139e97
commit d81b4dbf68

View file

@ -1138,47 +1138,59 @@ prompt_dir() {
truncate_to_unique) truncate_to_unique)
expand=1 expand=1
delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'} delim=${POWERLEVEL9K_SHORTEN_DELIMITER-'*'}
_p9k_prompt_length $delim local -i i=2
local -i real_delim_len=_P9K_RETVAL i=2 n=1 q=0
[[ $p[1] == / ]] && (( ++i )) [[ $p[1] == / ]] && (( ++i ))
[[ -n $parts[i-1] ]] && parts[i-1]="\${(Q)\${:-${(qqq)${(q)parts[i-1]}}}}"$'\2'
[[ $p[i,-1] == *["~!#\$^&*()\\\"'<>?{}[]"]* ]] && q=1
local -i d=${POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH:--1}
(( d >= 0 )) || d=real_delim_len
shortenlen=${POWERLEVEL9K_SHORTEN_DIR_LENGTH:-1}
(( shortenlen >= 0 )) && n=shortenlen
local parent="${PWD%/${(pj./.)parts[i,-1]}}" local parent="${PWD%/${(pj./.)parts[i,-1]}}"
for (( ; i <= $#parts - n; ++i )); do if (( i <= $#parts )); then
local dir=$parts[i] local mtime=()
if [[ -n $POWERLEVEL9K_SHORTEN_FOLDER_MARKER && zstat -A mtime +mtime -- ${(@)${:-{$i..$#parts}}/(#b)(*)/$parent/${(pj./.)parts[i,$match[1]]}} 2>/dev/null || mtime=()
-n $parent/$dir/${~POWERLEVEL9K_SHORTEN_FOLDER_MARKER}(#qN) ]]; then mtime="${(pj:\1:)mtime}"
parent+=/$dir else
(( q )) && parts[i]="\${(Q)\${:-${(qqq)${(q)dir}}}}" local mtime='good'
parts[i]+=$'\2' fi
continue if ! _p9k_cache_get $0 "${parts[@]}" || [[ -z $mtime || $mtime != $_P9K_CACHE_VAL[1] ]] ; then
fi _p9k_prompt_length $delim
local -i j=1 local -i real_delim_len=_P9K_RETVAL n=1 q=0
for (( ; j + d < $#dir; ++j )); do [[ -n $parts[i-1] ]] && parts[i-1]="\${(Q)\${:-${(qqq)${(q)parts[i-1]}}}}"$'\2'
local -a matching=($parent/$dir[1,j]*/(N)) [[ $p[i,-1] == *["~!#\$^&*()\\\"'<>?{}[]"]* ]] && q=1
(( $#matching == 1 )) && break local -i d=${POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH:--1}
done (( d >= 0 )) || d=real_delim_len
local -i saved=$(($#dir - j - d)) shortenlen=${POWERLEVEL9K_SHORTEN_DIR_LENGTH:-1}
if (( saved > 0 )); then (( shortenlen >= 0 )) && n=shortenlen
if (( q )); then for (( ; i <= $#parts - n; ++i )); do
parts[i]='${${${_P9K_D:#-*}:+${(Q)${:-'${(qqq)${(q)dir}}'}}}:-${(Q)${:-' local dir=$parts[i]
parts[i]+=$'\3'${(qqq)${(q)dir[1,j]}}$'}}\1\3''${$((_P9K_D+='$saved'))+}}' if [[ -n $POWERLEVEL9K_SHORTEN_FOLDER_MARKER &&
else -n $parent/$dir/${~POWERLEVEL9K_SHORTEN_FOLDER_MARKER}(#qN) ]]; then
parts[i]='${${${_P9K_D:#-*}:+'$dir$'}:-\3'$dir[1,j]$'\1\3''${$((_P9K_D+='$saved'))+}}' parent+=/$dir
(( q )) && parts[i]="\${(Q)\${:-${(qqq)${(q)dir}}}}"
parts[i]+=$'\2'
continue
fi fi
else local -i j=1
(( q )) && parts[i]="\${(Q)\${:-${(qqq)${(q)dir}}}}" for (( ; j + d < $#dir; ++j )); do
fi local -a matching=($parent/$dir[1,j]*/(N))
parent+=/$dir (( $#matching == 1 )) && break
done done
for ((; i <= $#parts; ++i)); do local -i saved=$(($#dir - j - d))
(( q )) && parts[i]='${(Q)${:-'${(qqq)${(q)parts[i]}}'}}' if (( saved > 0 )); then
parts[i]+=$'\2' if (( q )); then
done parts[i]='${${${_P9K_D:#-*}:+${(Q)${:-'${(qqq)${(q)dir}}'}}}:-${(Q)${:-'
parts[i]+=$'\3'${(qqq)${(q)dir[1,j]}}$'}}\1\3''${$((_P9K_D+='$saved'))+}}'
else
parts[i]='${${${_P9K_D:#-*}:+'$dir$'}:-\3'$dir[1,j]$'\1\3''${$((_P9K_D+='$saved'))+}}'
fi
else
(( q )) && parts[i]="\${(Q)\${:-${(qqq)${(q)dir}}}}"
fi
parent+=/$dir
done
for ((; i <= $#parts; ++i)); do
(( q )) && parts[i]='${(Q)${:-'${(qqq)${(q)parts[i]}}'}}'
parts[i]+=$'\2'
done
_p9k_cache_set "$mtime" "${parts[@]}"
fi
parts=("${(@)_P9K_CACHE_VAL[2,-1]}")
;; ;;
truncate_with_folder_marker) truncate_with_folder_marker)
if [[ -n $POWERLEVEL9K_SHORTEN_FOLDER_MARKER ]]; then if [[ -n $POWERLEVEL9K_SHORTEN_FOLDER_MARKER ]]; then