antigen
antigen copied to clipboard
Autocompletions from oh-my-zsh kubectl plugins don't work
Description
Completions from ~/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/kubectl/kubectl.plugin.zsh
do not work for me:
In the module it reads
if (( $+commands[kubectl] )); then
__KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion"
if [[ ! -f $__KUBECTL_COMPLETION_FILE ]]; then
kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE
fi
[[ -f $__KUBECTL_COMPLETION_FILE ]] && source $__KUBECTL_COMPLETION_FILE
unset __KUBECTL_COMPLETION_FILE
fi
Completion code gets written and sourced, but completion is not available at the prompt. All aliases defined by the plugin are there.
kubectl completion zsh > ~/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/kubectl/_kubectl
Gets me around, but there are are are other plugins exhibiting similar behaviour - e.g. npm
.
I expected putting
source <(kubectl completion zsh)
at the end of .zshrc
(after antigen apply
) to also get me around, but that is not the case.
Steps to reproduce
Make .zshrc
read:
source $HOME/.zsh/antigen.zsh
antigen use oh-my-zsh
antigen bundle kubectl
antigen apply
Expected behavior:
- Tab completion of `kubectl` command.
Software version
-
antigen version
:2.2.2
-
zsh --version
:5.7.1
-
uname -a
:5.3.0-40
Configuration
n/a
Per https://github.com/ohmyzsh/ohmyzsh/issues/6323 this can be fixed by adding this to your .zshrc:
# The following two modules (compinit and bashcompinit) are needed to get auto
# completion to work: https://github.com/ohmyzsh/ohmyzsh/issues/6323
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
You may have to run compaudit
and secure some directories to not be prompted each time about insecure directories.
Strangely I have currently somewhat similar problem, but maybe not exactly. Completion for subcommands work, for example k conf -> k config and k config use -> k config use-context However, following dynamic content (context name) - does not work: k config use-context -> .....
But if I execute source <(k completion zsh)
- it solves the problem and I see list of contexts when expanding command above. And when I put it to the end if .zshrc
- shell starts a tad slower, but the problem is gone
Hmm, same here.
zsh 5.5
and kubectl autocompletion doesn't work anymore without manual source ~/.zshrc
,
but some other completion works fine, like pip or docker.
python completion doesn't work too :\
Same for me with kubectl
, but other completions work fine.
Also adding the following doesn't work:
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
Strangely if running source <(kubectl completion zsh)
directly in the console it starts working even though this command is the last line in my .zshrc
so no other commands run after that
UPD: For me the way of fixing it was to comment out in the .antigen/init.zsh
the following lines:
# autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit
# compdef () {}
I know it's not the proper way of fixing it and that it can cause some other errors, but I'm heavily using kubectl
so I need autocompletion so much
Thank you for the workaround. It didn't work for me, because .antigen/init.zsh is (re-)generated by antigen, but it led me to a different workaround that did the trick for me: I put autoload -U +X compinit && compinit
before my compdef
s in my .zshrc
.
Hi all, compaudit
helped me to fix that issue.
on my macos apparently /usr/local/share/zsh/site-functions
and /usr/local/share/zsh
had 775 permission and were identified by compaudit
.
After fixing permission to 755 everything started to work
Hi all, I had a situation where I had to downgrade kubectl (via apt on Ubuntu). Afterwards kubectl autocompletion was not available any more, though it was in my plugins list in my ~/.zshrc
file. It seems it can be fixed by deleting the file ~/.oh-my-zsh/cache/kubectl_completion
and restarting the shell, at least that's what I did and it worked out without manually sourcing anything.
UPD: For me the way of fixing it was to comment out in the
.antigen/init.zsh
the following lines:# autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit # compdef () {}
This works me! But as @darioseidl mentioned .antigen/init.zsh
gets re-generated. You would need to comment this in the antigen.zsh
which is sourced before performing any antigen operations shown below
source /path-to-antigen/antigen.zsh # <------------ This file
# Load the oh-my-zsh's library.
antigen use oh-my-zsh
...
or
source /path-to-antigen/antigen.zsh # <------------ This file
antigen init .antigenrc
UPD: For me the way of fixing it was to comment out in the
.antigen/init.zsh
the following lines:# autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit # compdef () {}
This works me! But as @darioseidl mentioned
.antigen/init.zsh
gets re-generated. You would need to comment this in theantigen.zsh
which is sourced before performing any antigen operations shown belowsource /path-to-antigen/antigen.zsh # <------------ This file # Load the oh-my-zsh's library. antigen use oh-my-zsh ...
or
source /path-to-antigen/antigen.zsh # <------------ This file antigen init .antigenrc
I have removed the line
compdef () {}
from antigen.zsh and replaced it with
autoload -Uz compinit && compinit
Make sure cache have completions sub-directory.
mkdir $ZSH_CACHE_DIR/completions
Then open new tab, and everything is working fine.