Skip to content

Instantly share code, notes, and snippets.

@bps
Created March 23, 2011 14:29

Revisions

  1. bps created this gist Mar 23, 2011.
    29 changes: 29 additions & 0 deletions git_ps1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # via https://gist.github.com/623371

    if [[ $(declare -f __git_ps1) ]]; then
    export GIT_PS1_SHOWDIRTYSTATE=1
    export GIT_PS1_SHOWSTASHSTATE=1
    export GIT_PS1_SHOWUNTRACKEDFILES=1

    git_ps1_disable ()
    {
    _skip_git_ps1=1
    }
    git_ps1_enable ()
    {
    unset _skip_git_ps1
    }
    _update_prompt ()
    {
    local this_git_status=""
    if [ -z "${_skip_git_ps1}" ]; then
    this_git_status=$(__git_ps1 "(%s)")
    case $? in
    0 ) : ;;
    130 ) git_ps1_disable;; # If we break that last command because it's too slow, stop trying it
    esac
    fi
    export PS1=": \u@\h \w${this_git_status}; "
    }
    export PROMPT_COMMAND=_update_prompt
    fi