Fix for oh-my-zsh git-svn prompt slowness

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:

https://gist.github.com/2355834

6 thoughts on “Fix for oh-my-zsh git-svn prompt slowness

  1. Also, a “git config –global oh-my-zsh.hide-status 1″ will do the same thing without having to modify oh-my-zsh.

  2. 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!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>