zsh powerlevel10k 開啟git大工程時 慢/卡頓問題解決

ItsShowTime發表於2024-04-03

目錄
  • 參考連結
  • 正文

參考連結

  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

相關文章