使用了 oh-my-zsh 之后 cd some_dir 变得奇慢无比

发布时间: 2018-01-04 17:12:04 作者: 大象笔记

想用 strace 跟踪一下,发现 strace 并不支持内置的命令

strace cd ~/work/debugging/
strace: Can't stat 'cd': No such file or directory

网上学了一招

$ stty -echo
$ cat | strace zsh > /dev/null

但是,在这个执行环境下,无法重新卡顿的问题。

Google 了一下,发现

zsh -xv

可以打印出 zsh 的执行日志

+zsh:3> cd /home/zhongwei/work/warcraft
+omz_termsupport_precmd:1> emulate -L zsh                                                                                                                                                                   
+omz_termsupport_precmd:3> [[ true == true ]]
+omz_termsupport_precmd:4> return
+zsh:4> git_prompt_info
+git_prompt_info:1> local ref
+git_prompt_info:2> [[+git_prompt_info:2> git config --get oh-my-zsh.hide-status
+git_prompt_info:2> [[ '' != 1 ]]
+git_prompt_info:3> ref=+git_prompt_info:3> git symbolic-ref HEAD
+git_prompt_info:3> ref=refs/heads/master 
+git_prompt_info:5> parse_git_dirty
+parse_git_dirty:1> local STATUS=''
+parse_git_dirty:2> local -a FLAGS
+parse_git_dirty:3> FLAGS=( --porcelain ) 
+parse_git_dirty:4> [[+parse_git_dirty:4> git config --get oh-my-zsh.hide-dirty
+parse_git_dirty:4> [[ '' != 1 ]]
+parse_git_dirty:5> [[ 1 -gt 0 ]]
+parse_git_dirty:6> FLAGS+='--ignore-submodules=dirty' 
+parse_git_dirty:8> [[ '' == true ]]
+parse_git_dirty:11> STATUS=+parse_git_dirty:11> git status --porcelain '--ignore-submodules=dirty'
+parse_git_dirty:11> STATUS=+parse_git_dirty:11> tail -n1
+parse_git_dirty:11> STATUS='' 
+parse_git_dirty:13> [[ -n '' ]]
+parse_git_dirty:16> echo '%{%})'

卡在了

+parse_git_dirty:11> STATUS=+parse_git_dirty:11> git status --porcelain '--ignore-submodules=dirty'
+parse_git_dirty:11> STATUS=+parse_git_dirty:11> tail -n1

将 .zshrc 中 plugins 的 git 去掉之后,依旧卡顿,并且可以看到 git 的执行日志。

于是怀疑是 oh-my-zsh 的主题中还有 git 命令,搜索一下不包含 git 命令的主题

grep --files-without-match "git" ~/.oh-my-zsh/themes/*
/home/zhongwei/.oh-my-zsh/themes/cypher.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/duellj.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/evan.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/example.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/funky.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/imajes.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/mikeh.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/pure.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/rkj.zsh-theme
/home/zhongwei/.oh-my-zsh/themes/xiong-chiamiov.zsh-theme

将 .zshrc 中的 ZSH_THEME 设置成 pure 之后,被推荐了另外一个主题,说是作者要求,但是更换之后,发现依然有 git 执行的日志。

+repo_information:1> git_dirty
+git_dirty:2> git rev-parse --is-inside-work-tree
+git_dirty:4> git diff --quiet --ignore-submodules HEAD
+git_dirty:4> [ 0 -eq 1 ']'
+repo_information:1> echo '%F{blue}%{%}family_doctor_signing_patient_client%{%} %F{8}git/master %f'

将 .zshrc 中的 ZSH_THEME 设置成 example 之后,就没有这个问题了。

真折腾。。。

我是一名山东烟台的开发者,联系作者