Skip to content

Instantly share code, notes, and snippets.

@bps
Created March 23, 2011 14:29
Show Gist options
  • Save bps/883177 to your computer and use it in GitHub Desktop.
Save bps/883177 to your computer and use it in GitHub Desktop.
Sometimes __git_ps1 takes too long. This disables it when we ^C.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment