Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug#246305: zsh: completion for sudo doesn't add commands under root's path



On May 1,  1:02am, Clint Adams wrote:
} Subject: Re: Bug#246305: zsh: completion for sudo doesn't add commands und
}
} This is how to achieve the equivalent effects with the patch at the
} bottom

<Nodding.>

} Should I commit?

It'd be preferable to avoid declaring "local +h" if you don't need them.
If you declare them, then zsh has to save/restore the globals, which has
the side effect of causing a rehash, etc.

So I'd suggest something like:

 local -a cmdpath
 if zstyle -a ":completion:${curcontext}" command-path cmdpath &&
    [[ $#cmdpath -gt 0 ]]
 then
   local -a +h path
   local -A +h commands
   path=( $cmdpath )	# Resets $commands as a side-effect
 fi
 _alternative -O args "$defs[@]"

Remember that "local" is function-scoped, not block-scoped, so you don't
need { } around anything, nor do the local decls have to appear in the
same if-branch as the call to _alternative.



Messages sorted by: Reverse Date, Date, Thread, Author