Skip to content

Instantly share code, notes, and snippets.

@shoaibali
Last active March 21, 2016 09:58
Show Gist options
  • Save shoaibali/30bd81344f3e4ed1a64d to your computer and use it in GitHub Desktop.
Save shoaibali/30bd81344f3e4ed1a64d to your computer and use it in GitHub Desktop.
show color of git branch
# Avoid duplicates
export HISTCONTROL=ignoredups:erasedups
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend
# After each command, append to the history file and reread it
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_git_tag () {
git describe --tags 2> /dev/null
}
parse_git_branch_or_tag() {
local OUT="$(parse_git_branch)"
if [ "$OUT" == " ((no branch))" ]; then
OUT="($(parse_git_tag))";
fi
echo $OUT
}
##export PS1="\u@\h:\w\$(parse_git_branch_or_tag) $ "
##export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
function color_my_prompt {
local __user_and_host="\[\033[01;32m\]\u@\h"
local __cur_location="\[\033[01;34m\]\w"
local __git_branch_color="\[\033[31m\]"
#local __git_branch="\`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ')\"\`"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local __prompt_tail="\[\033[35m\]$"
local __last_color="\[\033[00m\]"
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "
}
color_my_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment