zshrc 在加载时在 iterm2 上输出神秘错误

zshrc outputing cryptic errors on iterm2 at loading

我是 osx 10.15.7 (Catalina) 上的 Mac 用户。 我最近用它更新了 brew 和升级的配方。 从那以后,我的终端变得不稳定并打印出这些错误:

_zulu_init_setup_completion:9: compinit: function definition file not found
/user/path/.zulu/packages/tipz/tipz.zsh:86: add-zsh-hook: function definition file not found
_zulu_init:48: promptinit: function definition file not found
_zulu_init:50: command not found: prompt
/user/path/.zprezto/init.zsh:14: is-at-least: function definition file not found
prezto: old shell detected, minimum required: 4.3.17
/user/path/.zshrc:19: promptinit: function definition file not found
/usr/local/Cellar/zplug/2.4.2/autoload/init.zsh:16: colors: function definition file not found
polling.zsh:17: add-zsh-hook: function definition file not found
# the following line is repeated at least 20 times
__zplug::core::core::get_interfaces:49: regexp-replace: function definition file not found
__zplug::core::core::prepare:67: compinit: function definition file not found
[zplug] ERROR: The loading of zplug was discontinued.
/user/path/.nvm/bash_completion:87: bashcompinit: function definition file not found
/user/path/.nvm/bash_completion:88: compinit: function definition file not found
/user/path/.nvm/bash_completion:95: command not found: complete
/user/path/.zshrc:35: command not found: gcloud
/user/path/google-cloud-sdk/completion.zsh.inc:1: bashcompinit: function definition file not found
/user/path/google-cloud-sdk/completion.zsh.inc:4: compinit: function definition file not found
/user/path/google-cloud-sdk/completion.zsh.inc:37: command not found: complete
/user/path/google-cloud-sdk/completion.zsh.inc:62: command not found: complete
/user/path/google-cloud-sdk/completion.zsh.inc:63: command not found: complete

我不是很精通 bash 我认为我的安装可能也很复杂(oh-my-zsh、prezto、powerlevel10k)。 我只想知道如何排除错误并修复它。

我的 zshrc 如下所示

#
# Executes commands at the start of an interactive session.
#
# Authors:
#   Sorin Ionescu <sorin.ionescu@gmail.com>
#
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 
# Initialise zulu plugin manager
source "${ZULU_DIR:-"${ZDOTDIR:-$HOME}/.zulu"}/core/zulu"
zulu init

# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
  source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi

# Customize to your needs...
autoload -Uz promptinit
promptinit
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
# export PATH="$PATH:$HOME/.rvm/rubies/ruby-2.4.1/bin/"

# loading ZPLUG
export ZPLUG_HOME=/usr/local/opt/zplug
source $ZPLUG_HOME/init.zsh

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:/user/path/Library/Python/3.7/bin:$PATH"
export GOOGLE_PROJECT="$(gcloud config get-value project)"
export GOOGLE_APPLICATION_CREDENTIALS="/user/path/PROJECTS/personal/k8s/gcp-k8s-credentials.json"

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/user/path/google-cloud-sdk/path.zsh.inc' ]; then . '/user/path/google-cloud-sdk/path.zsh.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/user/path/google-cloud-sdk/completion.zsh.inc' ]; then . '/user/path/google-cloud-sdk/completion.zsh.inc'; fi

# iziwork key
export GITHUB_AUTH_TOKEN=xxx

编辑

Bash版本:echo $BASH_VERSION给出一个空行。

Zsh 版本:5.7.1

prezto: old shell detected, minimum required: 4.3.17

检查你的 zsh 版本

zsh --version

最后有几个问题,随着 brew 的升级,.zshrc 文件中的一些路径没有得到正确升级:

  • fpath in ~/.config/zulu 指向旧版本或不正确的 zsh 版本(特别是 .../zsh/function)
  • zplug 的路径不正确
  • 在设置 gcloud 路径之前调用了一些 gcloud 命令

所以

#this
/usr/local/Cellar/zsh/5.8/share/zsh/functions
#became 
/usr/local/Cellar/zsh/5.8_1/share/zsh/functions

#this 
export ZPLUG_HOME=/usr/local/Cellar/zplug/2.4.2/autoload/zplug
#became this
export ZPLUG_HOME=/usr/local/Cellar/zplug/2.4.2