In these days, I’m using ZSH(https://ohmyz.sh/). It has many handy features and supports useful plugins. One day, I’ve noticed a slowness issue. Basically, the prompt was not shown right after running a command. It was interesting because it only happened in the git repositories. To fix this issue, I needed to understand what’s happening first.
When you run
zsh with a
--help parameter, you can see many options. Among them,
-x are useful ones to dig into the problem.
When you run
zsh -xv, every command that ZSH runs will be shown. In the git repo, I pressed
enter multiple times and checked logs to figure out which command is slow. There might be some better ways but I just looked at the terminal. I saw that there was a bit freeze when the below line was shown.
To show helpful information on the prompt, ZSH has many defined functions. Git related functions are defined in
git.zsh. As you can see, that command is from
Those functions are generally called by ZSH themes and plugins. In my case,
avit theme, I’m currently using, uses it to set
It is possible to fix or optimize
git_prompt_status() function in
git.zsh. However, I realized that it was the information that I didn’t need actually. So, I decided to remove that. One way is to remove that line in the theme directory.
.oh_my_zsh is a git repo. So, modifying the code in there could make an issue to update ZSH. Instead of that, I simply override
RPROMPT value in
.zshrc. This is a safer approach.
Note that a problem line could vary depending on your theme and plugins. When you have some issues,
zsh -vx will help you to point a problem command.