Created
August 2, 2013 18:37
-
-
Save huyhong/6142267 to your computer and use it in GitHub Desktop.
Martin's colored git branch & RVM/gemset .bash_profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[ -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