I was dying a slow death from the slowness of my zsh prompt when using oh-my-zsh‘s git plugin and a repository managed by git-svn. I finally decided to do something about it today.
I tracked the slowness down to the parse_git_dirty
function in oh-my-zsh/lib/git.zsh
. This function calls git status
which seems to be quite slow in my environment. My fix was to replace the oh-my-zsh version of the git_prompt_info
function with a version that doesn’t call parse_git_dirty
. This means that I can’t get the little checkmark (“✔”) or “X” (well actually “✗”) that shows whether my working copy is dirty or not, but it’s worth it to me to not have my prompt lag like crazy.
To fix this, I pasted the following into my ~/.zshrc
:
This was driving me crazy… very helpful thanks.
Excellent job, helped a lot ..thanks
Also, a “git config –global oh-my-zsh.hide-status 1” will do the same thing without having to modify oh-my-zsh.
thank you.. this was killing me as well…
awesome!! very helpful thanks..
Heyo! I google for “zsh git prompt slow” and what do you know – your blog is the first hit!
I just switched to zsh (after a lot of prodding from a couple of friends of mine), so don’t have a good zsh-specific solution yet. But in my bash setup I wrote a function to replace the prompt with the faster one for NFS-mounted repos:
# Return “yes” if the repository is on an “nfs” mount
function __is_slow_storage() {
STAT_OPT=”-L –file-system –format=\”%T\””
if [ $OSTYPE == “Darwin” ]; then
STAT_OPT=”-L -f \”%HT\””
fi
if [ $(stat $STAT_OPT $1) == “nfs” ]; then
echo “yes”
else
echo “no”
fi
}
# Simplify git prompt for NFS-mounted directories to avoid delays
function __fast_git_ps1() {
if [ $(__is_slow_storage `pwd`) == “yes” ]; then
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ” (“${ref#refs/heads/}”?)”
else
eval “__git_ps1″
fi
}
# My Git-aware prompt
export PS1=”\n\w\[33[0;33m\]\$(__fast_git_ps1)\[\e[0m\]\n\[\e[36;1m\]\u@$USER_COLOR\h\[\e[32;1m\] \$ \[\e[0m\]”
I’m actually using prezto instead of oh-my-zsh and loving it!
Note: it is possible to disable the git status from any oh-my-zsh theme, and on a “per repository” basis.
What I do is to keep a prompt with the nice git status (✔ / ✗) but use the following line to disable that only on slow git repos:
â–¶ git config –add oh-my-zsh.hide-status 1
If I want to re-enable the status, it’s as easy as
â–¶ git config –unset-all oh-my-zsh.hide-status
A thing that I do often lately is to temporarily change my prompt. I use this not just for slowness; in fact, I mainly use it for when I’m posting examples in PRs, issues, etc. and my regular prompt would be too “noisy”.
Do a bunch of stuff…
Hi there!
Something I found was that the oh-my-zsh prompt was significantly slower with a vanilla OSX git (1.7.12.4 (Apple Git-37)). Upgrading to a new version via brew (2.2.0) removed the slowness problem entirely!
This override is not necessary, and since it was very slow/annoying for me and this is a top google result… here’s the git config for it.
git config –global oh-my-zsh.hide-dirty 1
Worked like a charm for me. Looks like it was added or fixed November 2014.
You pasted your own git_prompt_info function in ~/.zshrc? I did that and nothing happened. I thought maybe it would override the built-in one, but it doesn’t.
Pingback: oh-my-zsh slow, but only for certain Git repo - QuestionFocus