35

The zshcompsys man-page says:

INITIALIZATION

If the system was installed completely, it should be enough to call the shell function compinit from your initialization file; see the next section. However, the function compinstall can be run by a user to configure various aspects of the completion system.

zsh can't find the commands though:

genesis% compinit
zsh: command not found: compinit
genesis% compinstall
zsh: command not found: compinstall
genesis% echo $PATH
/home/ravi/bin:/home/ravi/.gem/ruby/2.4.0/bin:/home/ravi/bin:/home/ravi/.gem/ruby/2.4.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/local/heroku/bin:/home/ravi/.cabal/bin:/home/ravi/.local/share/fzf/bin:/usr/local/heroku/bin:/home/ravi/.cabal/bin
genesis%

I'm lead to ask this question because when starting zsh I get:

tmuxinator.zsh:20: command not found: compdef

How do I get zsh to find these completion commands?

Tom Hale
  • 28,728
  • 32
  • 139
  • 229

3 Answers3

63

This is the same issue I got on my mac. I am using zsh shell.

Zsh Compdef error

Compdef is basically a function used by zsh for load the auto-completions. The completion system needs to be activated. If you’re using something like oh-my-zsh then this is already taken care of, otherwise you’ll need to add the following to your ~/.zshrc

autoload -Uz compinit
compinit

Completion functions can be registered manually by using the compdef function directly like this compdef . But compinit need to be autoloaded in context before using compdef.

  • 2
    I tried this but got "compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask" Guessing that is because I don't use homebrew so this answer may be a problem for people like me. – Jackie Jan 04 '21 at 20:34
  • This is what I needed on MacOS 12.6. Thanks! – jakub.g Nov 15 '22 at 12:41
  • If you're using oh-my-zsh and still getting this, make sure to put your `compdef` _after_ the `source $ZSH/oh-my-zsh.sh` line in `~/.zshrc`. – David Lord Aug 10 '23 at 01:40
14

Answer to the question as asked

Access these commands by running:

$ autoload -Uz compinstall && compinstall

It will load a guided wizard, I quit as soon as I had the option to Save and exit.

Then reload the shell:

$ exec zsh

More general answer

It appears that the new user configuration was not run.

Run it by:

$ autoload -Uz zsh-newuser-install && zsh-newuser-install -f
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
0

I experienced the same issue.

For me I did the following:

  • Closed the current terminal
  • Ran the command brew doctor to fix any brew package concern
  • And finally ran the command rm -f ~/.zcompdump; compinit
Promise Preston
  • 231
  • 2
  • 5