Show RVM Gemset, Git branch, & Git dirty in bash promt
Sometimes you get confused and make a mistake from terminal. It happens. Often it happens from not knowing your context while working. This helps keep that from happening.
Open your ~/.bash_profile file and add the following.
Show current RVM gemset (if any)
function rvm_version {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
[ "$version" != "" ] && version="$version"
local full="$version$gemset"
[ "$full" != "" ] && echo " $full"
}
Show Git branch (if any)
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " "${ref#refs/heads/}" "
}
Show Git dirty (uncommitted changes)
function parse_git_dirty {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "• "
}
Putting it all together
export PS1="\w$(rvm_version)$(parse_git_branch)$(parse_git_dirty)$ "
Ive added some colors to mine which you can do if you like but it looks like this...
Written by David Morrow
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Related Tags
#bash
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#