My command line says `complete:13: command not found: compdef `
When I use a terminal like iTerm or Hyper, right as I boot it up, the first message I get is:
complete:13: command not found: compdef
I don't know what this is from, and how to get rid of it. This message does not show up on the default terminal app though.
I am using zsh.
This is the same issue I got on my mac OS. I am using zsh shell.
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.
After more research, I have found my answer. There was a block in my .zprofile:
export NVM_DIR="/Users/Aaron/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
The last line loads compdef. But when doing this it caused some sort of confliction. All I needed to do was comment out:
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
And the annoying error went away. And the best part: I still have zsh tab completion.
Update: The issue is already fixed in newer versions of nvm. Update nvm using the install script and the error should go away (tested with v0.37.2)
I had the same problem, after some research I found that the root of the issue was a nvm code snippet in the .zshrc (could also be .zprofile) file.
export NVM_DIR="/Users/Aaron/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Like suggested in another answer, commenting the third line does solve the issue, but, surprise surprise, bash completion for nvm commands will not be available anymore.
The real problem is at the end of the bash_completion
script:
# complete is a bash builtin, but recent versions of ZSH come with a function
# called bashcompinit that will create a complete in ZSH. If the user is in
# ZSH, load and run bashcompinit before calling the complete function.
if [[ -n ${ZSH_VERSION-} ]]; then
autoload -U +X bashcompinit && bashcompinit
fi
But to call bashcompinit, compinit must have been called before and at this time it isn‘t. (I think this should/could be fixed in the nvm script, I will create an issue on github.)
If you want to have nvm completion, you can just call compinit yourself before the script runs.
autoload -Uz compinit
compinit -i
export NVM_DIR="/Users/Aaron/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
The -i option tells compinit to silently ignore all insecure files and directories, which might prevent further errors in the future.