kubectx: Completions not working with oh-my-zsh on Linux

I am working on Linux with oh-my-zsh and I can’t get completions to work.

I have updated my fpath line in ~/.oh-my-zsh/oh-my-zsh.sh to be: fpath=($ZSH/functions $ZSH/completions /home/username/kubectx/completion $fpath)

When I run echo $fpath, I get the expected output: ... /home/username/kubectx/completion ...

The directory above (/home/username/kubectx/completion) contains only one script, which is the kubectx.zsh script in the repo.

Have I done something wrong in the setup?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

Had the same issue - in my case, probably after a MacOS upgrade or something, the used zsh switched from homebrew-installed zsh (/usr/local/bin/zsh) to the MacOS’s own zsh, /bin/zsh. You can compare their versions via /usr/local/bin/zsh --version and /bin/zsh --version. To see the current version you are using, check echo $ZSH_VERSION, and also check cat /etc/shells to see a list of available shells.

If you are on MacOS zsh, you need to switch to the one comes from Homebrew, since that one has /usr/local/share/zsh/site-functions in FPATH - the location which brew install kubectx installs the completions.

To switch to Homebrew zsh, simply check your /etc/shells, if /usr/local/bin/zsh is missing, add it:

sudo bash -c 'echo /usr/local/bin/zsh >> /etc/shells'

then

chsh -s /usr/local/bin/zsh

Open a new shell and verify via echo $ZSH_VERSION

Edit: Noticed that the original issue was on Linux, anyway, this can be help for people having similar issue on MacOS.

Works now! Thanks @edmeister.

My final fpath is: fpath=($ZSH/functions $ZSH/completions $fpath).

I put the kubectx.zsh file in $ZSH/completions folder and renamed it to _kubectx.

The file names should start with an underscore to be loaded by zsh.

Completion functions for commands are stored in files with names beginning with an underscore _, and these files should be placed in a directory listed in the $fpath variable. You can add a directory to $fpath by adding a line like this to your ~/.zshrc file:

fpath=(~/newdir $fpath)