Completions Provided by Plugins Not Working
Description
compdef in plugin scripts have no effect.
Steps to reproduce
Minimal .zshrc:
if [ ! -d "$HOME/.antigen" ]; then
git clone --branch master https://github.com/zsh-users/antigen.git "$HOME/.antigen"
fi
source $HOME/.antigen/antigen.zsh
antigen bundle fanzeyi/zsh-at
antigen apply
The zsh-at plugin provides an @ command, which provided its own completion function, but when I hit tab after the @ command, I got default filename completions.
Expected behavior:
- The `_zsh_at_completion` function provided by the plugin should be used for completions for the `@` command.
Software version
-
antigen version: v2.2.2 (8846aa9) -
zsh --version: zsh 5.7.1 (x86_64-redhat-linux-gnu)
More information
By inspecting the cached script init.zsh, I found that:
- The
compinitfunction was called in_antigen_compinit, which was called by aprecmdhook; - This
precmdhook got triggered only after the init script was sourced, and before the first command prompt; - All the plugin scripts sourced in the init script called an empty
compdeffunction defined in the init script, with the zsh completion system uninitialized. - When I got to a command prompt, no completion provided by plugins worked at all.
I found the code regarding completions quite confusing. Why not call _antigen_compinit directly instead of using a hook? Why is there an empty compdef function?
I found the same, the compdef function is a no-op in the cache file (see https://github.com/zsh-users/antigen/blob/8846aa902047992e86816cbd941acc86646bd83b/src/ext/cache.zsh#L59). Why is that?
Related issue: https://github.com/ohmyzsh/ohmyzsh/issues/9139.
I'm having issue with the gcloud plugin completion not working
I've added a complete -p at the end of .zshrc that yields
* Zsh will start quickly but prompt will jump down after initialization.
For details, see:
https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt
-- console output produced during zsh initialization follows --
complete -o default -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil
complete -o nospace -o default -F _python_argcomplete gcloud
complete _bash bash
Then at the prompt, doing a complete -p as the first command:
$ complete -p
complete _bash bash
$
When sourcing the completion script at the prompt and issuing complete -p once more I then get
$ source google-cloud-sdk/completion.zsh.inc
$ complete -p
complete -o default -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil
complete -o nospace -o default -F _python_argcomplete gcloud
complete _bash bash
$
And completion is working from then on.
Somehow, the complete config vanishes while processing the first prompt...
Any idea ?
Greetings,
I have this issue to, and so do many others. I think it keeps coming up because it's so hard to narrow down what the issue is.
Related: https://github.com/zsh-users/antigen/issues/701 https://github.com/zsh-users/antigen/issues/583
Also, this user might have found something releveant: https://unix.stackexchange.com/questions/670676/zsh-autocompletion-for-function-based-on-git-why-is-compdef-not-working-in-zsh/670942
When I type
type compdefin my zsh, it sayscompdef is a shell function from /usr/share/zsh/functions/Completion/compinit, whereas when I include it in my.zshrcit printscompdef is a shell function from /home/dario/.antigen/init.zsh.
That is related to what @mcornella mentioned above https://github.com/zsh-users/antigen/issues/698#issuecomment-666681300, which seems to be the heart of the matter.
I found the same, the
compdeffunction is a no-op in the cache file (seehttps://github.com/zsh-users/antigen/blob/8846aa902047992e86816cbd941acc86646bd83b/src/ext/cache.zsh#L59
). Why is that? Related issue: ohmyzsh/ohmyzsh#9139.
It seems this is the reason: "Defer bundle loading to antigen-apply command" https://github.com/zsh-users/antigen/pull/513
Commenting out these two lines in antigen makes the oh-my-zsh completions work again:
autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit
compdef () {}