zsh powerlevel10k 打开git大工程时 慢/卡顿问题解决

参考链接

  1. https://blog.csdn.net/a_ran/article/details/72847022 oh-my-zsh git 慢/卡顿问题解决_用了oh my zsh 后速度变慢-CSDN博客
  2. https://github.com/romkatv/powerlevel10k/issues/714 don't git status specific directories · Issue #714 · romkatv/powerlevel10k
  3. https://www.cnblogs.com/rootid/p/9486262.html git代码自动补全 - rootid - 博客园
  4. https://github.com/romkatv/powerlevel10k/issues/1712 [Feature request] Conditionally disable vcs segment · Issue #1712 · romkatv/powerlevel10k
  5. https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh git/contrib/completion/git-prompt.sh at master · git/git

正文

以前只使用oh-my-zsh的时候, 遇到git卡了, 搜索就有参考资料1, 设置

git config --add oh-my-zsh.hide-dirty 1
git config --add oh-my-zsh.hide-status 1

后来好像在oh-my-zsh源码里面还看到一个oh-my-zsh.hide-info

但是, 使用powerlevel10k的时候, 上面的方法就不管用了
找了很久, 终于在搜索bing powerlevel10k skip git status的时候找到了p10k的issue(参考资料2)

There are several options. I suggest trying them in the specified order. They progressively disable more and more parts of vcs prompt segment.
Go to the repo and run this command:

git config --local bash.showUntrackedFiles false

Restart zsh. If it's still too slow, run another command:

git config --local bash.showDirtyState false

Restart zsh. If it's still too slow, revert these changes:

git config --local --unset bash.showUntrackedFiles
git config --local --unset bash.showDirtyState

Open ~/.p10k.zsh and search for POWERLEVEL9K_VCS_DISABLED_WORKDIR_PATTERN. If your config is new enough, you'll see this:

# Don't show Git status in prompt for repositories whose workdir matches this pattern.
# For example, if set to '~', the Git repository at $HOME/.git will be ignored.
# Multiple patterns can be combined with '|': '~(|/foo)|/bar/baz/*'.
typeset -g POWERLEVEL9K_VCS_DISABLED_WORKDIR_PATTERN='~'

Change this parameter as suggested in the comments. If you don't have this parameter, add it.
Restart zsh. If it's still too slow, revert your changes, open ~/.p10k.zsh and add this:

typeset -g POWERLEVEL9K_VCS_DISABLED_DIR_PATTERN='(/some/dir|/another/dir)(|/*)'

注: 搜了搜git config的配置项,好像这个在fish等地方也有用, 并且搜到了参考资料3, .git-sh-prompt.sh
后来又在参考资料4的帖子看到作者发了参考资料5, 就是git官方的git-prompt.sh

posted @ 2024-04-03 01:03  ItsShowTime  阅读(185)  评论(0编辑  收藏  举报