Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active April 24, 2018 10:34
Show Gist options
  • Save chernjie/f67d40d1dfb935c59699 to your computer and use it in GitHub Desktop.
Save chernjie/f67d40d1dfb935c59699 to your computer and use it in GitHub Desktop.
source git-ps1.source
#!/usr/bin/env bash
# Source git completion and git prompts
command -v __git_ps1 > /dev/null ||
for i in git-completion.bash git-prompt.sh
do
echo source ~/bin/$i
source ~/bin/$i
done
if declare -f __git_ps1 2>&1 >/dev/null
then
if test -z "$ZSH_VERSION"
then
# assume Bash
test -n "$SSH_CLIENT" || test -n "$REMOTEHOST" && currentHost='@\[\e[33;1m\]\h\[\e[0m\]'
export PS1='$(_e="$?"; test "$_e" -eq 0 && echo || echo "\[\e[36;1m\]$_e " )\[\e[33;1m\]\t \[\e[37;1m\]\u'$currentHost'\[\e[0m\]:\[\e[32;1m\]$(__pwd_ps1)$(echo -n -e "\033]0;$@ "$(__pwd_ps1)"\007")\[\e[0m\]$(__git_ps1 "(\[\e[36;1m\]%s\[\e[0m\])")\n\[\e[31;1m\]\$\[\e[0m\] '
fi
fi
export GIT_PS1_SHOWCOLORHINTS=true
export GIT_PS1_DESCRIBE_STYLE=branch
case $1 in
'*'|'+'|dirty)
export GIT_PS1_SHOWDIRTYSTATE=$( [ -z $GIT_PS1_SHOWDIRTYSTATE ] && echo true || echo)
;;
'$'|stash)
export GIT_PS1_SHOWSTASHSTATE=$( [ -z $GIT_PS1_SHOWSTASHSTATE ] && echo true || echo)
;;
%|untrack|track)
export GIT_PS1_SHOWUNTRACKEDFILES=$([ -z $GIT_PS1_SHOWUNTRACKEDFILES ] && echo true || echo)
;;
u|up|upstream)
export GIT_PS1_SHOWUPSTREAM=$( [ -z $GIT_PS1_SHOWUPSTREAM ] && echo true || echo)
;;
off)
export GIT_PS1_SHOWDIRTYSTATE=
export GIT_PS1_SHOWSTASHSTATE=
export GIT_PS1_SHOWUNTRACKEDFILES=
export GIT_PS1_SHOWUPSTREAM=
;;
''|default)
# default toggles
export GIT_PS1_SHOWDIRTYSTATE=$( [ -z $GIT_PS1_SHOWDIRTYSTATE ] && echo true || echo)
export GIT_PS1_SHOWSTASHSTATE=$( [ -z $GIT_PS1_SHOWSTASHSTATE ] && echo true || echo)
export GIT_PS1_SHOWUNTRACKEDFILES=$([ -z $GIT_PS1_SHOWUNTRACKEDFILES ] && echo true || echo)
export GIT_PS1_SHOWUPSTREAM=$( [ -z $GIT_PS1_SHOWUPSTREAM ] && echo true || echo)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment