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

Re: detect if command has a completion function



On Sat, Aug 29, 2020 at 9:47 AM vapnik spaknik <vapniks@xxxxxxxxx> wrote:
>
> The reason I need this capability is to help with a function I've written for cleaning up .zshrc files.
> ... I wrote a function which checks the commands mentioned in those "compdef _gnu_generic" lines, and removes any that are not present on the system:

Don't bother removing the compdef lines, just remove their results.
That way you won't have to add things back again if you install one of
those missing programs.

completed=( ${(k)_comps:#([^[:alnum:]]*)} )
installed=( ${(k)builtins} ${(k)functions} ${(k)commands} )
not_installed=( ${completed:|installed} )
unset '_comps['${^not_installed}']'

Just be sure you have done all your zmodloads and autoloads before
executing the above, or you'll remove completions for some builtins
and functions.

Older zsh will not have the ${name:|arrayname} syntax so you might
have to resort to

not_installed=( ${completed:#${~:-(${(j:|:)${(q)installed}})}} )




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