oh-my-zsh's prompt is slow: how to fix this

16,425

Solution 1

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> '

Solution 2

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/*

Solution 3

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

Solution 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.

Share:
16,425

Related videos on Youtube

floatingpurr
Author by

floatingpurr

...where is my Dr. Pepper!?

Updated on September 18, 2022

Comments

  • floatingpurr
    floatingpurr over 1 year

    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.

    • GoingMyWay
      GoingMyWay almost 4 years
    • Jamie
      Jamie over 3 years
      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.
  • ospider
    ospider over 3 years
    Great tips, it was git_prompt_info causing my issue. Thanks
  • Lelouch Lamperouge
    Lelouch Lamperouge over 2 years
    Nice tip with grep thing. Saved me a ton of effort :P
  • user2401543
    user2401543 over 2 years
    if this is git_prompt_info issue this command will fix the issue: git config oh-my-zsh.hide-info 1 --global