29

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
floatingpurr
  • 425
  • 1
  • 5
  • 9
  • See this question. https://stackoverflow.com/questions/12765344/oh-my-zsh-slow-but-only-for-certain-git-repo – GoingMyWay Aug 04 '20 at 06: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 Aug 31 '20 at 21:35

6 Answers6

36

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> '
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
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/*
pkoo
  • 171
  • 1
  • 2
14

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.

Sunny Patel
  • 241
  • 2
  • 3
5

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!

MartinCR
  • 151
  • 1
  • 2
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.

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.

davenpcj
  • 161
  • 1
  • 2