1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-25 16:31:57 +00:00

limit the number of looked-at tokens to 32

This commit is contained in:
romkatv 2020-01-11 15:47:59 +01:00
parent 2db236fc69
commit 251ec93396

View file

@ -97,44 +97,46 @@ typeset -gA _p9k_skip_arg=(
) )
function _p9k_next_token() { function _p9k_next_token() {
if (( $#tokens == aln[-1] )); then if (( $#tokens )); then
aln[-1]=() if (( $#tokens == aln[-1] )); then
alp[-1]=() aln[-1]=()
if (( $#tokens == alf[-1] )); then alp[-1]=()
alf[-1]=() if (( $#tokens == alf[-1] )); then
(( e = 0 )) alf[-1]=()
(( e = 0 ))
else
(( e = 1 ))
fi
else else
(( e = 1 )) (( e = 1 ))
fi fi
else
(( e = 1 ))
fi
while (( $#tokens )); do while (( c-- > 0 )); do
token=$tokens[1] token=$tokens[1]
shift 1 tokens tokens[1]=()
if (( $+galiases[$token] )); then if (( $+galiases[$token] )); then
(( $aln[(eI)p$token] )) && return (( $aln[(eI)p$token] )) && return
n=p$token n=p$token
s=$galiases[$token] s=$galiases[$token]
elif (( e )); then elif (( e )); then
return return
elif (( $+aliases[$token] )); then elif (( $+aliases[$token] )); then
(( $aln[(eI)p$token] )) && return (( $aln[(eI)p$token] )) && return
n=p$token n=p$token
s=$aliases[$token] s=$aliases[$token]
elif [[ $token == (#b)?*.(?*) ]] && (( $+saliases[$match[1]] )); then elif [[ $token == (#b)?*.(?*) ]] && (( $+saliases[$match[1]] )); then
(( $aln[(eI)s$match[1]] )) && return (( $aln[(eI)s$match[1]] )) && return
n=s$match[1] n=s$match[1]
s=${saliases[$match[1]]%% #} s=${saliases[$match[1]]%% #}
else else
return 0 return 0
fi fi
aln+=$n aln+=$n
alp+=$#tokens alp+=$#tokens
[[ $s == *' ' ]] && alf+=$#tokens [[ $s == *' ' ]] && alf+=$#tokens
[[ -o interactive_comments ]] && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s}) [[ -o interactive_comments ]] && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s})
done done
fi
token= token=
return 1 return 1
@ -182,108 +184,110 @@ function _p9k_extract_commands() {
local -r id='$(<->|[[:alpha:]_][[:IDENT:]]#)' local -r id='$(<->|[[:alpha:]_][[:IDENT:]]#)'
local -r var="\$$id|\${$id}|\"\$$id\"|\"\${$id}\"" local -r var="\$$id|\${$id}|\"\$$id\"|\"\${$id}\""
local -i e local -i e c=32
local skip n s r local skip n s r
local -a aln alp alf v commands match mbegin mend local -a aln alp alf v commands match mbegin mend
[[ -o interactive_comments ]] && local tokens=(${(Z+C+)1}) || local tokens=(${(z)1}) [[ -o interactive_comments ]] && local tokens=(${(Z+C+)1}) || local tokens=(${(z)1})
while (( $#tokens )); do () {
if (( $#tokens == aln[-1] )); then while (( $#tokens )); do
aln[-1]=() if (( $#tokens == aln[-1] )); then
alp[-1]=() aln[-1]=()
if (( $#tokens == alf[-1] )); then alp[-1]=()
alf[-1]=() if (( $#tokens == alf[-1] )); then
(( e = 0 )) alf[-1]=()
(( e = 0 ))
else
(( e = $#skip ))
fi
else else
(( e = $#skip )) (( e = $#skip ))
fi fi
else
(( e = $#skip ))
fi
while (( $#tokens )) || break; do while (( c-- > 0 )) || return; do
token=$tokens[1] token=$tokens[1]
shift 1 tokens tokens[1]=()
if (( $+galiases[$token] )); then if (( $+galiases[$token] )); then
(( $aln[(eI)p$token] )) && break (( $aln[(eI)p$token] )) && break
n=p$token n=p$token
s=$galiases[$token] s=$galiases[$token]
elif (( e )); then elif (( e )); then
break break
elif (( $+aliases[$token] )); then elif (( $+aliases[$token] )); then
(( $aln[(eI)p$token] )) && break (( $aln[(eI)p$token] )) && break
n=p$token n=p$token
s=$aliases[$token] s=$aliases[$token]
elif [[ $token == (#b)?*.(?*) ]] && (( $+saliases[$match[1]] )); then elif [[ $token == (#b)?*.(?*) ]] && (( $+saliases[$match[1]] )); then
(( $aln[(eI)s$match[1]] )) && break (( $aln[(eI)s$match[1]] )) && break
n=s$match[1] n=s$match[1]
s=${saliases[$match[1]]%% #} s=${saliases[$match[1]]%% #}
else else
break break
fi
aln+=$n
alp+=$#tokens
[[ $s == *' ' ]] && alf+=$#tokens
[[ -o interactive_comments ]] && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s})
done
if [[ $token == '<<'(|-) ]]; then
_p9k_next_token || break
r=$token
while true; do
while _p9k_next_token && [[ $token != ';' ]]; do done
while _p9k_next_token && [[ $token == ';' ]]; do done
[[ $token == (|$r) ]] && break
done
continue
fi
if [[ -n $skip ]]; then
if [[ $skip == ']' ]]; then
if (( $+_p9k_term[$token] )); then
skip=$_p9k_skip_arg[$token]
[[ $token == '()' ]] || _p9k_commands+=($commands)
commands=()
fi fi
elif [[ $token == $~skip ]]; then aln+=$n
skip= alp+=$#tokens
fi [[ $s == *' ' ]] && alf+=$#tokens
continue [[ -o interactive_comments ]] && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s})
fi done
r=${token#<0-255>} if [[ $token == '<<'(|-) ]]; then
if (( $+_p9k_skip_token[$r] )); then _p9k_next_token || return
if (( $+_p9k_skip_token[$token] )); then r=$token
skip=$_p9k_skip_token[$token] while true; do
while _p9k_next_token && [[ $token != ';' ]]; do done
while _p9k_next_token && [[ $token == ';' ]]; do done
[[ $token == (|$r) ]] && break
done
continue continue
fi fi
if (( $+_p9k_redirect[$r] )); then
skip='*' if [[ -n $skip ]]; then
if [[ $skip == ']' ]]; then
if (( $+_p9k_term[$token] )); then
skip=$_p9k_skip_arg[$token]
[[ $token == '()' ]] || _p9k_commands+=($commands)
commands=()
fi
elif [[ $token == $~skip ]]; then
skip=
fi
continue continue
fi fi
fi
if [[ $token == *=* ]]; then r=${token#<0-255>}
v=${(S)token/#(<->|([[:alpha:]_][[:IDENT:]]#(|'['*[^\\](\\\\)#']')))(|'+')=} if (( $+_p9k_skip_token[$r] )); then
if (( $#v < $#token )); then if (( $+_p9k_skip_token[$token] )); then
[[ $v == '(' ]] && skip='\)' skip=$_p9k_skip_token[$token]
continue continue
fi
if (( $+_p9k_redirect[$r] )); then
skip='*'
continue
fi
fi fi
fi
if [[ $token == *'$'* ]]; then if [[ $token == *=* ]]; then
if [[ $token == $~id ]]; then v=${(S)token/#(<->|([[:alpha:]_][[:IDENT:]]#(|'['*[^\\](\\\\)#']')))(|'+')=}
n=${${token##[^[:IDENT:]]}%%[^[:IDENT:]]} if (( $#v < $#token )); then
[[ $token == *'"' ]] && v=("${(@P)n}") || v=(${(P)name}) [[ $v == '(' ]] && skip='\)'
tokens[1,0]=(${(qq)v}) continue
continue fi
fi fi
fi
commands+=${:-${(Q)${~token}}} if [[ $token == *'$'* ]]; then
skip=']' if [[ $token == $~id ]]; then
done n=${${token##[^[:IDENT:]]}%%[^[:IDENT:]]}
[[ $token == *'"' ]] && v=("${(@P)n}") || v=(${(P)name})
tokens[1,0]=(${(qq)v})
continue
fi
fi
commands+=${:-${(Q)${~token}}}
skip=']'
done
}
_p9k_commands+=($commands) _p9k_commands+=($commands)
_p9k_commands=(${(u)_p9k_commands:#('(('*'))'|'`'*'`'|'$'*)}) _p9k_commands=(${(u)_p9k_commands:#('(('*'))'|'`'*'`'|'$'*)})