antigen icon indicating copy to clipboard operation
antigen copied to clipboard

Kubectl completion broken after `antigen list`

Open shane-lawrence opened this issue 7 years ago • 6 comments

The problem only occurs when I'm using antigen. If I uninstall antigen and just run autoload -U compinit; compinit in the shell, kubectl completion works fine.

Problem

kubectl tab completion sometimes gives the following error: _kubectl:4: bad set of key/value pairs for associative array

Steps to Reproduce (with plugins)

  1. Install software and dotfiles as described in Environment section.
  2. Cleanup rm ~/.zcompdump; antigen reset.
  3. Open a new instance of zsh from the OS (not from inside the old shell).
  4. Type kubectl <tab>.
  5. Observe the error.

Steps to Reproduce (without plugins)

  1. Install the software without any additional plugins, as described in the Environment section.
  2. Cleanup rm ~/.zcompdump; antigen reset.
  3. Open a new instance of zsh from the OS (not from inside the old shell).
  4. Type kubectl <tab>.
  5. Observe that completion appears normally.
  6. Run the command antigen list.
  7. Type kubectl <tab>.
  8. Observe the error.

Workaround

This command appears to solve the problem temporarily: source /usr/local/share/zsh/site-functions/_kubectl (that is actually a link to /usr/local/Cellar/kubernetes-cli/1.8.2/share/zsh/site-functions/_kubectl, which is identical to the output of kubectl completion zsh).

The problem is not resolved by adding that exact source line to the end of .zshrc, and the issue will recur when a new shell is opened from the OS, but it will not recur if a new shell is opened from inside the old shell.

Environment

Software

macOS 10.13, zsh 5.4.2, kubernetes-cli 1.8.2 and antigen v2.2.1 installed with Homebrew 1.3.6.

Configuration

.zshrc

export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH

export EDITOR=code

source ~/.antigenrc

.antigenrc (with plugins)

source /usr/local/share/antigen/antigen.zsh
antigen use oh-my-zsh
antigen bundles <<EOBUNDLES
    brew
    cask
    common-aliases
    docker
    encode64
    gem
    git
    history
    jsontools
    kubectl
    osx
    perms
    python
    rails
    ruby
    zsh-users/zsh-completions
EOBUNDLES
antigen theme robbyrussell
antigen apply 

.antigenrc (without plugins)

source /usr/local/share/antigen/antigen.zsh
antigen use oh-my-zsh
antigen theme robbyrussell
antigen apply 

shane-lawrence avatar Nov 08 '17 21:11 shane-lawrence

Same question here. I found that this can be fixed by executing source <(kubectl completion zsh) again in zsh. Maybe antigen did something after zsh has loaded ~/.zshrc?

PureWhiteWu avatar Jan 10 '18 17:01 PureWhiteWu

@PureWhiteWu I have source <(kubectl completion zsh) in my ~./zshrc as well and still require the temporary work around @shane-lawrence mentioned above.

pluttrell avatar Jan 10 '18 20:01 pluttrell

@shane-lawrence thanks, your workaround worked for me as well

mlushpenko avatar Jan 29 '18 14:01 mlushpenko

I was seeing this with a gcloud install without antigen and I fixed it by moving the gcloud lines above the oh-my-zsh declarations - I think the kubectl plugin doesn't load if it can't find the command.

Since I switched to antigen the issue has returned.

silasdavis avatar Nov 13 '18 15:11 silasdavis

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.

allen-servedio avatar Jan 16 '21 02:01 allen-servedio

I recently ran into the same issue, and I think I've traced it back as far as antigen's cache feature, at least as a contributing factor. If disabled (via ANTIGEN_CACHE=false prior to loading antigen), then things work as expected.

I believe the cause is in antigen.zsh's cache code setup, line 1822, where a precmd hook is setup to call compinit again. It looks to be trying to run only once, as it deletes itself from the hook list after it runs, but it's already cleared the kubectl completion defs.

FWIW, I thinks this is also related to #701, and to #698.

HOWEVER, I have no intent on fixing it - this was the last straw for me and antigen. It fully appears as if this plugin manager is dead (see #725). I'm moving on to some other tool.

eengstrom avatar Feb 09 '21 22:02 eengstrom