Bash Terminal Customizations for RVM and Git with git-completion.sh

In process of customizing my bash terminal prompt in my ~/.bash_profile, I thought it would be great to show which RVM and Git branch I was on.

You can make yours look similar to this: Screenshot of what Navid’s Bash Terminal Looks Like

The solution is to use git-completion.sh. You can get it via git:

git clone git://gist.github.com/776299.git

Or you can get it from git-completion

** NOTE ** Backup your ~/.bash_login.sh file before you make changes to it in case you want to revert!

  1. Copy the .git-completion.sh file to ~/.git-completion.sh.
  2. Then replace your PS1 line in your ~/.bash_login, if you have one, with the following, if you want yours to look like the screenshot linked to above.

* Be sure to open a new terminal window to see the changes.

# Bash Prompt Colors, includes colors for RVM and Git
source ~/.git-completion.sh

__client () { local mypwd=${PWD##*Consulting/}; echo -n ${mypwd%%/*} ;}

if [[ -s /Users/rab/.rvm/scripts/rvm ]] ; then source /Users/rab/.rvm/scripts/rvm ; fi

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

# last two parts of pwd in the prompt
# 01 = bg_black; 32 = green; 33 = yellow; 34 = blue
if [ -n "$PS1" ]; then
    PS1='\[\033[00;34m\][${rvm_ruby_string:-$(ruby -v | awk "{print \\$1 \"-\" \\$2}")}]\[\033[00m\] \[\033[01;32m\]$(__client)\[\033[00m\]:\[\033[00;32m\]$(echo "$(basename $(dirname "$(pwd)"))/$(basename "$(pwd)")")\[\033[00m\]$(__git_ps1 " (\[\033[00;33m\]%s\[\033[00m\])") \$ '
    stty discard '^-'
fi
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
Facebook Twitter Email

Leave a Reply