Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
detect if command has a completion function
- X-seq: zsh-users 26044
- From: vapnik spaknik <vapniks@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: detect if command has a completion function
- Date: Sat, 29 Aug 2020 16:47:08 +0000 (UTC)
- Archived-at: <https://zsh.org/users/26044>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2020-08/301108111.164161.1598719628682%40mail.yahoo.com>
- Authentication-results: zsh.org; iprev=pass (sonic307-55.consmr.mail.gq1.yahoo.com) smtp.remote-ip=98.137.64.31; dkim=pass header.d=yahoo.com header.s=s2048 header.a=rsa-sha256; dmarc=skipped; arc=none
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1598719630; bh=RXQEGkZR1VlZkPXJmd4ow+XaRiDMNXrvo0tMiOhRcew=; h=Date:From:To:Subject:References:From:Subject; b=YXN+lp+Nh7Y3QCcd421+AXBY+Rq2QMzih/n+pjtSwn3U3ReAbpMQDIhko9bytGWrxGR8L3yZL7LUb1wopi0A8EN7fksHr6s8aq4L+ZbiR3veCFGGa5RmclkJNJ+1pl3z1DR2t9PAQ+mvoE3stsZPDE6GWMFDnH3f+6j1LvoBw3GZPQw1ogWmfD7HyBmPJ9uXOYXawiKdTKp70Tr8+lfBGRBPn6z2OKSapAAzU1M2pcQoiQcHSOc2GWQdsdl84nPkGH+iOQdZg+l3grqoZOspaPvyza2Hs1C3kYXypqw3v+WV/PnMxD/H4FGvNig8Z1hIrZEV95VyXejf2SGflmw7NQ==
- List-archive: <http://www.zsh.org/sympa/arc/zsh-users>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-users.zsh.org>
- List-owner: <mailto:zsh-users-request@zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-users>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-users>
- References: <301108111.164161.1598719628682.ref@mail.yahoo.com>
- Sender: zsh-users-request@xxxxxxx
Hi,
how can I detect if a given command has a completion function, from within another function?
I want to loop over many commands quickly, so I want to avoid resorting to searching directories with find if possible.
The reason I need this capability is to help with a function I've written for cleaning up .zshrc files.
I tend to collect lots of "compdef _gnu_generic cmd1 cmd2..." lines in my .zshrc, but many of the commands flagged for completion with _gnu_generic are not present on other systems where I install the same .zshrc. 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:
function cleanup-compdefs() {
local okcmds=() numcols=120
for cmd in ${(i)$(grep -e "^compdef _gnu_generic" ~/.zshrc|sed 's/compdef _gnu_generic//')}; do
if which ${cmd} &>/dev/null; then
okcmds+="$(basename ${cmd})"
fi
done
local line i=1
while [[ ${i} -le ${#okcmds} ]]; do
line="compdef _gnu_generic"
while [[ ${#line} -lt ${numcols} ]]; do
line+=" ${okcmds[${i}]}"
i=$((${i} + 1))
done
echo "${line}"
done
}
However, I also want it to check which of the commands already have completion functions defined, so that they can also be removed.
Can anyone help?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author