fix bugs in _p10k completion

- Fix segments+=("$segments") -> segments+=("$reselem")
- Add local declarations for loop variables to prevent scope leaks
- Fix hadkkSecond typo -> hadSecond
- Fix hardcoded '=' -> use $equals variable
- Fix missing '[' in -s segment flag description
- Add missing 'finalize' subcommand
- Add local for arguments in __p10k_segment
This commit is contained in:
MenkeTechnologies 2026-04-01 15:29:08 -04:00
commit f2bd8daf90

40
_p10k
View file

@ -4,6 +4,7 @@ __p10k_getpart(){
local -aU keys lines sides segments __p10k_prompt_selectors local -aU keys lines sides segments __p10k_prompt_selectors
local -A reply local -A reply
local equals resparts resline resside reselem resCnt hadSecond hadThird
lines=() lines=()
sides=() sides=()
segments=() segments=()
@ -29,7 +30,7 @@ __p10k_getpart(){
__p10k_prompt_selectors+=("$resline/$resside$equals") __p10k_prompt_selectors+=("$resline/$resside$equals")
sides+=("$resside") sides+=("$resside")
else else
segments+=("$segments") segments+=("$reselem")
__p10k_prompt_selectors+=("$resline/$resside/$reselem$equals") __p10k_prompt_selectors+=("$resline/$resside/$reselem$equals")
fi fi
@ -39,7 +40,7 @@ __p10k_getpart(){
p10k display -a "$line/*" p10k display -a "$line/*"
keys=( ${(uk)reply} ) keys=( ${(uk)reply} )
hadkkSecond=false hadSecond=false
hadThird=false hadThird=false
for k in ${keys[@]};do for k in ${keys[@]};do
@ -59,7 +60,7 @@ __p10k_getpart(){
done done
if [[ $hadSecond == true ]]; then if [[ $hadSecond == true ]]; then
__p10k_prompt_selectors+=("$line/*=") __p10k_prompt_selectors+=("$line/*$equals")
fi fi
if [[ $hadThird == true ]]; then if [[ $hadThird == true ]]; then
@ -145,18 +146,20 @@ __p10k_display(){
__p10k_segment(){ __p10k_segment(){
arguments=( local arguments
'-t[segment main content; will undergo prompt expansion]:text'
'-i[segment icon; default is empty]:icon' arguments=(
'-r[icon is a symbolic reference that needs to be resolved]' '-t[segment main content; will undergo prompt expansion]:text'
'+r[icon is already resolved and should be printed literally; for example,⭐]' '-i[segment icon; default is empty]:icon'
'-b[background color; for example, empty value means]:bg' '-r[icon is a symbolic reference that needs to be resolved]'
'-f[foreground color; for example, empty value means]:fg' '+r[icon is already resolved and should be printed literally]'
'-s:segment state for the purpose of applying styling options]:state' '-b[background color; for example, empty value means]:bg'
'-c[if empty after parameter expansion and process substitution]:condition' '-f[foreground color; for example, empty value means]:fg'
'-e[segment main content will undergo parameter expansion and process]' '-s[segment state for the purpose of applying styling options]:state'
'+e[segment main content should not undergo parameter expansion and process]' '-c[if empty after parameter expansion and process substitution]:condition'
'(- * :)-h[print this help message]' '-e[segment main content will undergo parameter expansion and process]'
'+e[segment main content should not undergo parameter expansion and process]'
'(- * :)-h[print this help message]'
) )
_arguments -S -s $arguments && return 0 _arguments -S -s $arguments && return 0
@ -170,6 +173,7 @@ function _p10k(){
__p10k_commands=( __p10k_commands=(
'configure:run interactive configuration wizard' 'configure:run interactive configuration wizard'
'finalize:finish instant prompt initialization'
'reload:reload configuration' 'reload:reload configuration'
'segment:print a user-defined prompt segment' 'segment:print a user-defined prompt segment'
'display:show, hide or toggle prompt parts' 'display:show, hide or toggle prompt parts'
@ -191,11 +195,7 @@ function _p10k(){
verb=$words[1] verb=$words[1]
curcontext="${curcontext%:*:*}:p10k-$verb:" curcontext="${curcontext%:*:*}:p10k-$verb:"
case $verb in case $verb in
configure) configure|reload|finalize)
_message 'no more arguments'
ret=1
;;
reload)
_message 'no more arguments' _message 'no more arguments'
ret=1 ret=1
;; ;;