From: Bart Schaefer <schaefer@brasslantern.com>
To: vapnik spaknik <vapniks@yahoo.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: detect if command has a completion function
Date: Sat, 29 Aug 2020 11:33:19 -0700 [thread overview]
Message-ID: <CAH+w=7Z1XwGeqmOV0ZRnkwPepisyCwUxqf-zWLRq3x_ojnw+sQ@mail.gmail.com> (raw)
In-Reply-To: <301108111.164161.1598719628682@mail.yahoo.com>
On Sat, Aug 29, 2020 at 9:47 AM vapnik spaknik <vapniks@yahoo.com> 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}})}} )
next prev parent reply other threads:[~2020-08-29 18:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <301108111.164161.1598719628682.ref@mail.yahoo.com>
2020-08-29 16:47 ` vapnik spaknik
2020-08-29 17:21 ` Marc Cornellà
[not found] ` <AM6PR02MB56389D8F9832FA6C58D8EF6E84530@AM6PR02MB5638.eurprd02.prod.outlook.com>
2020-08-29 17:38 ` vapnik spaknik
2020-08-29 18:33 ` Bart Schaefer [this message]
2020-08-29 19:27 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7Z1XwGeqmOV0ZRnkwPepisyCwUxqf-zWLRq3x_ojnw+sQ@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=vapniks@yahoo.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).