oh-my-zsh 非常慢(加载时间大约 10 秒)

oh-my-zsh very slow (load time about 10 seconds)

我正在使用:

Mac OS X 10.10.5 (Yosemite)
zsh 5.0.5
oh-my-zsh

问题是,终端加载时间太慢,大约 10 秒,即使打开新的终端选项卡也是如此。

我尝试了此博客上的解决方案 post:http://osxdaily.com/2010/05/06/speed-up-a-slow-terminal-by-clearing-log-files/ 但那对我没有帮助。

sudo rm -rf /private/var/log/asl/*.asl

谢谢

node 给我带来了麻烦,这里是有效的解决方案:

在我的.zshrc

# configure node version manager
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" --no-use # This loads nvm
alias node='unalias node ; unalias npm ; nvm use default ; node $@'
alias npm='unalias node ; unalias npm ; nvm use default ; npm $@'

更多信息请访问: https://github.com/creationix/nvm/issues/539#issuecomment-245791291

谢谢

请对主题中的所有git提示代码进行注释。

我的 mac 上的 zsh 非常慢。任何命令,如 cd、ls 都需要 2-5 秒,但在我对主题中的所有 git 提示代码进行注释后,情况变得完全不同。

再次享受顺畅!

这些是我用来优化 shell 启动速度和减少执行命令延迟的步骤 -

  1. 如果你用的是powerlevel9k,那么我会建议立即切换到powerlevel10k

Powerlevel10k is a theme for Zsh. It emphasizes speed, flexibility and out-of-the-box experience. It is a reimplementation of the popular Powerlevel9k zsh theme. It looks exactly the same given the same configuration but renders prompt 10-100 times faster. It's optimized on every level of the stack, all the way down to using a patched version of libgit2 that can scan a repo 4 times faster than the original. It can remove Zsh startup lag even if it's not caused by a theme with features such as Instant Prompt.

  1. 转到首选项 -> 配置文件 -> 常规 -> 命令和 select 选项命令而不是登录 Shell 并将下面的命令粘贴到它附近的框中。
login -pfq username /usr/local/bin/zsh -il

现在打开新标签时,您不会看到打印的最后登录时间。如果 zsh 不在位置 /usr/local/bin/zsh 中,您将需要使用 brew 安装 zsh。 mac 提供的默认 zsh 在 /usr/bin/zsh 并且可能使用像 5.2 这样的旧版本,当与 iTerm 或 oh-my-zsh 一起使用时可能会导致速度变慢。

  1. 要在 zsh 中快速粘贴,请在终端中执行以下命令。
mkdir -p $ZSH_CUSTOM/lib && touch $ZSH_CUSTOM/lib/misc.zsh
  1. 第 2 点应该已经解决了缓慢的登录时间问题。但为了安全起见,请执行以下命令
mkdir -p .hushlogin
  1. 您可能正在使用大量插件,它们运行缓慢且会造成延迟。您需要指出这些插件并将其删除。为此,您将需要 zsh 分析。关注此 link 了解更多详情 -

https://stevenvanbael.com/profiling-zsh-startup

我知道这是一个很老的问题,但我尝试了所有以前的答案,一段时间后问题又回来了。我做了 git 完全摆脱 oh-my-zsh。但真正的罪魁祸首是 .zsh-history。我的历史文件包含 1000 多个命令并且正在减慢 zsh。清除后,zsh 从 10 秒加载到 3 秒。

这是一个自动执行此操作的简单脚本。

HISTORY="~/.zsh-history" # Path to zsh history file
HISTORY_LOG="path/to/where/you/wan't/to/save/history"
MAX_HISTORY=100 # Maximum lines to keep in history

if [[ $(expr $(wc -l < $HISTORY) \> $MAX_HISTORY) = "1" ]]; then
    cat $HISTORY >> $HISTORY_LOG && echo '' > $HISTORY
fi

在启动时将此脚本添加到 运行,它会在超过 100 行时清除您的历史记录。我将它保存到另一个位置,以防以后我不想在其中找到任何东西。

您还可以将脚本更改为始终在您的历史记录中保留 100 行。也就是去掉前n行,让行数保持100行。不过我个人比较喜欢这种做法。