Search code examples
zshrbenv

Error message when starting terminal. [zsh]


When I start my terminal I get this message:

/usr/lib/rbenv/libexec/../completions/rbenv.bash:16: command not found: complete
~ % 

Everything else seems normal. I don't get the message when I run tmux, only when I start a new terminal.

Here's my ~/.zshrc file:

# load custom executable functions
for function in ~/.zsh/functions/*; do
  source $function
done

# extra files in ~/.zsh/configs/pre , ~/.zsh/configs , and ~/.zsh/configs/post
# these are loaded first, second, and third, respectively.
_load_settings() {
  _dir="$1"
  if [ -d "$_dir" ]; then
    if [ -d "$_dir/pre" ]; then
      for config in "$_dir"/pre/**/*(N-.); do
        . $config
      done
    fi

    for config in "$_dir"/**/*(N-.); do
      case "$config" in
        "$_dir"/pre/*)
          :
          ;;
        "$_dir"/post/*)
          :
          ;;
        *)
          if [ -f $config ]; then
            . $config
          fi
          ;;
      esac
    done

    if [ -d "$_dir/post" ]; then
      for config in "$_dir"/post/**/*(N-.); do
        . $config
      done
    fi
  fi
}
_load_settings "$HOME/.zsh/configs"

# aliases
[[ -f ~/.aliases ]] && source ~/.aliases
alias sz='source ~/.zshrc'

# Local config
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"

# rbenv config
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

What is causing this and how can I get rid of it? I can call up my version of Ruby successfully and I've run rbenv init and rbenv rehash already.

rbenv version
2.3.0 (set by /home/drempel/.rbenv/version)

ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

Solution

  • There was an issue posted on the github page for rbenv regarding the rbenv init script causing issues with zsh users. This was fixed in a later version. The answer there was to change eval "$(rbenv init -)" to eval "$(rbenv init - zsh)". I did this but it did not clear the error message. After reading my ~/.zshrc file closer I realized it was loading files from ~/.zsh/configs.

    In ~/.zsh/configs/post/path.zsh there was another rbenv init config:

    # ensure dotfiles bin directory is loaded first
    PATH="$HOME/.bin:/usr/local/sbin:$PATH"
    
    # load rbenv if available
    if command -v rbenv >/dev/null; then
      eval "$(rbenv init - --no-rehash)"
    fi
    
    # mkdir .git/safe in the root of repositories you trust
    PATH=".git/safe/../../bin:$PATH"
    
    export -U PATH
    

    I changed the line eval "$(rbenv init - --no-rehash)" to reflect eval "$(rbenv init - zsh --no-rehash)" and this resolved my issue.