Skip to content

Instantly share code, notes, and snippets.

@gaveen
Created July 6, 2011 11:55
Show Gist options
  • Save gaveen/1067055 to your computer and use it in GitHub Desktop.
Save gaveen/1067055 to your computer and use it in GitHub Desktop.
# .bashrc
# Cool bash prompt (with git goodness)
function parse_git_branch {
BRANCH_PROMPT=$(__git_ps1)
if [ -n "$BRANCH_PROMPT" ]; then
BR_GIT_STATUS=$(get_git_status)
echo $BRANCH_PROMPT$BR_GIT_STATUS
fi
}
function get_git_status() {
if current_git_status=$(git status | grep 'be committed' 2> /dev/null); then
echo "✗"
fi
}
PS1="\[\033[1;32m\][\u@\h \W\[\033[0;33m\]\$(parse_git_branch)\[\033[1;32m\]]\$\[\033[0m\] "
@gaveen
Copy link
Author

gaveen commented Jul 10, 2011

Decided to go with:

GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1

function parse_git_branch {
    if [ -d ./.git ]; then
        BRANCH_PROMPT=$(__git_ps1)
        echo $BRANCH_PROMPT
    fi
}

PS1="\[\033[1;32m\][\u@\h \W\[\033[0;33m\]\$(parse_git_branch)\[\033[1;32m\]]\$\[\033[0m\] "

Yours is simpler. Anyway I chose to run __git_ps1 only on dirs with a './.git' dir (eventhough __git_ps1 can handle that). Plus this way gets rid of the leading space. Now that I got the bike-shed done, going back to work. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment