News for hackers. Stuff that matters.
Re:How to Set Up Git Completion and Repo State on OS X by peff on Wednesday May 29, 2013 @01:52AM (#5784826)
That prompt can be really slow, as it runs `__git_ps1` multiple times (through several branches of the conditional, and then for the final output). On my git.git repository, running `time __git_ps1` takes about .085s. If I hit the "cyan" condition in the prompt, we run it three times, and doing `time eval "echo \"$PS1"\""` takes about 0.263s, which feels noticeably laggy.

Changing it to cache the result, like this:

   export PS1=$LIGHT_GRAY"\u@\h"'$(
    g=$(__git_ps1 " (%s)")
    if [[ "$g" =~ \*\)$ ]]
    then echo "'$YELLOW'$g"
    elif [[ "$g" =~ \+\)$ ]]
    then echo "'$MAGENTA'$g"
    else echo "'$CYAN'$g"
    fi)'$BLUE" \w"$GREEN": "
drops it back down to the .085s range.

There are no comments on this comment yet.