32

I'm using macOS 10.15.2 with iTerm2, zsh 5.7.1 and oh-my-zsh (theme robbyrussell).

I noticed that the prompt print is slightly slow respect to the bash one. For example, if I press enter, cursor initially goes at the beginning of the next line then, after a little while, the shell prompt comes in and the cursor is moved to its natural position. For example, if → ~ is the prompt when I'm in my home folder, and [] is my cursor, when I press enter I see:

0 - Idle status

→ ~ []

1 - Immediately after pressing enter

[]

2 - Back to idle status

→ ~ []

This slowness is particularly evident when I quickly press enter multiple times. In this case, I see some blank lines. This is what I see

→ ~
→ ~
→ ~

→ ~

→ ~


→ ~
→ ~
→ ~

→ ~ []

I come from bash shell and when I use bash, there is not such a slowness. I'm not sure this is an issue of oh-my-zsh or its natural behavior. I'd like to know more about this and, eventually, how to fix it. Thanks.

PS: the problem comes from oh-my-zsh and it persists even if I disable all the plugins.

PPS: I previously posted this question on SO. Thanks to user1934428 for his help and for suggesting me to move this question here.

2
  • 1
    See this question. stackoverflow.com/questions/12765344/…
    – GoingMyWay
    Commented Aug 4, 2020 at 6:08
  • I had this same issue. It wasn't related to being in a git repository. Interestingly, upon a fresh install of zsh -- i.e., after removing the config folder ~/.oh-my-zsh and reinstalling with the script on GitHub -- I noticed that the lag time was lower. It quickly increased to around 0.5 seconds per command with some time.
    – Jamie
    Commented Aug 31, 2020 at 21:35

7 Answers 7

40

I don't know what oh-my-zsh puts in the prompt by default. Maybe it tries to identify the version control status, that's a very popular prompt component which might be time-consuming.

To see what's going on, turn on command traces with set -x.

→ ~ 
→ ~ set -x
trace of the commands that are executed to calculate the prompt
→ ~ 
trace of the commands that are executed to calculate the prompt
→ ~ set +x
+zsh:3> set +x
→ ~ 
→ ~ 

If the trace is so long that it scrolls off the screen, redirect it to a file with

exec 2>zsh.err

This directs all error messages to the file, not just the trace. To get traces and errors back on the terminal, run

exec 2>/dev/tty

You can customize the trace format through PS4. This is a format string which can contain prompt escapes. For example, to add precise timing information:

PS4='%D{%s.%9.}+%N:%i> '
1
  • 1
    Great tips, it was git_prompt_info causing my issue. Thanks
    – ospider
    Commented Sep 30, 2020 at 8:39
20

Checking if git dir is dirty seems to be causing the delay.

To speed up shell response, disable checking if dir is dirty by running in your terminal :

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

Remember to restart all your shells.

17

I had the same issue with it, and it was also the git_prompt_info which causes the shell to slow down. Be aware, that some oh-my-zsh themes use the git plugin sort of "hard coded" in their propmpts.

So consider one from the list you can get with this command

grep --files-without-match "git" ~/.oh-my-zsh/themes/*
3
  • Nice tip with grep thing. Saved me a ton of effort :P Commented Aug 20, 2021 at 22:39
  • 4
    if this is git_prompt_info issue this command will fix the issue: git config oh-my-zsh.hide-info 1 --global Commented Sep 15, 2021 at 19:48
  • Thanks a ton! Picking up a theme from list fixed the slowness. Much appreciated.
    – tj-recess
    Commented Jan 18, 2023 at 5:54
8

I fixed the issue by modifying ~/.zshrc and uncommenting this env variable:

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
DISABLE_UNTRACKED_FILES_DIRTY="true"

I hope it helps!

4

I fixed this in my laptop going to the ~/.oh-my-zsh folder, then ran git pull. There was around ~1200 commits pending. Then I close the iTerm and open it again. You'll get a prompt of oh-my-zsh being updated.

2

Mac users: +prompt_git is what's taking so long but a new Xcode license is the real culprit.

If you use git that is bundled with Xcode, it's likely that there's an updated license that you needed to accept.

Run sudo xcodebuild -license and accept the new license, your ZSH prompt should return to normal speed.

1
  • This answer helped me find a fix: installing git with brew install git and then making sure that /opt/homebrew/bin appears on my PATH before /usr/bin meant that /opt/homebrew/bin/git became the new default (check with which git). Now the prompt loads at least 2-3x faster!
    – chimbo
    Commented Feb 8 at 22:28
0

vscode dev container terminal prompt was being slow for me, taking several seconds to return to prompt after completing any command. set -x showed the issue was with a git ls-files command being used to update the branch/dirty text in the prompt for a large repo. Oddly git ls-files itself wasn't slow.

Setting git config codespaces-theme.hide-status 1 solved it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .