I have the git-prompt.sh script setup in my .bashrc file which gives me the useful git information in my prompt. This is great for small repos, but when I cd into a large repo, it can take a 30+ seconds, for the prompt to respond since it needs to review the git repo first.

It is possible to set up my .bashrc so that I can either whitelist my small repos for the git prompt to display, or blacklist my large repos so it doesn't load the git prompt?
Alternatively, I'd be happy with a flag/variable that I have to set to enable the git prompt.

The relevant part of my .bashrc looks like this:

# Git prompt options
source ~/.git-prompt.sh

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 " (\[\033[01;33m\]%s\[\033[00m\])")\$ '
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (\[\033[01;33m\]%s\[\033[00m\])")\$ '
unset color_prompt force_color_prompt

Look at the code - the real work is done in a function __git_ps1, which is called from inside the prompt.

Replace this function by your own function, e.g.

# this is only a outline of possible code 
function myFancyGitPS1() {
   case $(pwd) in
           __git_ps1 " (\[\033[01;33m\]%s\[\033[00m\])"
  • groans It's always the obvious solutions that are so hard to see... Thanks heaps :) It's working perfectly now. – Stephen RC Mar 12 '13 at 21:58

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.