Skip to content

Instantly share code, notes, and snippets.

@dguerizec
Last active January 8, 2016 15:22
Show Gist options
  • Save dguerizec/ec51597585e4ea7da756 to your computer and use it in GitHub Desktop.
Save dguerizec/ec51597585e4ea7da756 to your computer and use it in GitHub Desktop.
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
GIT_PS1_SHOWUPSTREAM="auto verbose"
source ~/bin/git-prompt.sh
PROMPT_TIME=${PROMPT_TIME:-yes}
PROMPT_ELAPSED_SECONDS=${PROMPT_ELAPSED_SECONDS:-no}
_red="\[\e[01;31m\]"
_green="\[\e[01;32m\]"
_yellow="\[\e[01;33m\]"
_blue="\[\e[01;34m\]"
_purple="\[\e[01;35m\]"
_cyan="\[\e[01;36m\]"
_white="\[\e[01;37m\]"
_grey="\[\e[00m\]"
last=$(date +%s)
__git_prompt () {
PS1=$(
[ $? -ne 0 ] && echo -n -e "${_red}8{" || echo -n -e "${_green}:]"
echo -n -e " ${_green}\u@\h"
if [ "$PROMPT_TIME" ]; then
echo -n -e " $(date +%H:%M:%S)"
fi
if [ "$PROMPT_ELAPSED_SECONDS" = "yes" ]; then
now=$(date +%s)
echo -n -e " [$(( $now - $last ))s]"
last=$now
fi
d=$(git rev-parse --show-toplevel 2>/dev/null)/
if [ $? -eq 0 ]; then
pre=$(basename $d)
if [ "$PWD/" = "$d" ]; then
cwd='';
else
cwd="${PWD#$d} "
fi
echo -n -e " ${_purple}$pre${_white}$(__git_ps1) ${_yellow}${cwd}\$"
else
echo -n " ${_blue}$PWD \$"
fi
echo -n -e "${_grey} "
)
}
PROMPT_COMMAND='__git_prompt'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment