Skip to content

Instantly share code, notes, and snippets.

@huyhong
Created August 2, 2013 18:37
Show Gist options
  • Save huyhong/6142267 to your computer and use it in GitHub Desktop.
Save huyhong/6142267 to your computer and use it in GitHub Desktop.
Martin's colored git branch & RVM/gemset .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
bash_prompt() {
#git
local status=$(git status 2> /dev/null | grep 'working directory clean')
local dirty=''
if [ -z "$status" ]; then
local dirty='*'
fi
local branch=$(git branch 2> /dev/null | grep -e "\* " | sed "s/^..\(.*\)/\1/")
if [ -z "$branch" ]; then
export PS1="[$(date +%H:%M) \u@\[\033[33m\]\h\[\033[39m\]:\w] "
else
export PS1="[$(date +%H:%M) \u@\[\033[33m\]\h\[\033[39m\]:\w \[\033[32m\]$branch\[\033[36m\]$dirty\[\033[39m\]] "
fi
# RVM
n_cols=$(tput cols)
rvm_prompt="$(rvm-prompt)"
let rvm_ppos=$n_cols-${#rvm_prompt}
tput sc # save cursor
tput cuf $rvm_ppos; tput setaf 1 # right justified and in red
echo -n $rvm_prompt
tput sgr0 # may not always work as expected
tput rc # restore cursor
}
PROMPT_COMMAND=bash_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment