Skip to content

Instantly share code, notes, and snippets.

@chrishiestand
Last active August 29, 2015 14:07
Show Gist options
  • Save chrishiestand/1421a85a7fc8f0d4c17a to your computer and use it in GitHub Desktop.
Save chrishiestand/1421a85a7fc8f0d4c17a to your computer and use it in GitHub Desktop.
Bash PS1 for git
exists() {
if [ -z "$1" ]; then
return 99;
fi
type -t "$1" 2>&1 1>/dev/null
}
if ! exists _command && ! shopt -oq posix; then
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
elif exists brew && [ -f $(brew --prefix)/etc/bash_completion ]; then #homebrew
. $(brew --prefix)/etc/bash_completion
if [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
. /usr/local/etc/bash_completion.d/git-completion.bash
else
logger -t homedir "Cannot find git bash completion, try installing git-core+bash_completion"
fi
fi
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = "yes" ]; then
if exists __git_ps1; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 " \[\e[0;36m\](%s)\[\e[0m\]")\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
fi
else
if exists __git_ps1; then
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (%s)")\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
fi
unset color_prompt force_color_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment