Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't zsh execute command compdef?

I have installed zsh and oh my zsh on Ubuntu 18.04. I would like to use autocompletion for kubectl. Therefore I have added source <(kubectl completion zsh) to my ~/.zshrc file.

On execution of this script zsh gets the following error:

complete:13: command not found: compdef

The kubectl documentation states that when one gets the error above, you should put the following on top of the .zshrc file:

autoload -Uz compinit
compinit

After doing this and restarting the terminal, I get the same error.

In a git-issue I found the following helped people with a common issue:

#This will perform chmod g-w for each file returned by compaudit to remove write access for group
compaudit | xargs -I % chmod g-w "%"
#This will perform chown to current user (Windows and Linux) for each file returned by compaudit
compaudit | xargs -I % chown $USER "%"
#Remove all dump files (which normally speed up initialization)
rm ~/.zcompdump*
#Regenerate completions file
compinit

zsh logs the following while running the script:

kubescript:12457: command not found: _bash_comp

Unfortunately this did not solve my problem. What else can I do to fix my issue? Or even still: what can I do to find out what is causing it?

like image 359
Robert van der Spek Avatar asked Oct 08 '19 09:10

Robert van der Spek


Video Answer


1 Answers

I fixed the error by using the following code in .zshrc:

# K8s auto-complete
autoload -U +X compinit && compinit
source <(kubectl completion zsh)

You may also do it using oh-my-zsh plugin if you use oh-my-zsh.

like image 162
Aldekein Avatar answered Oct 08 '22 07:10

Aldekein