Skip to content

Instantly share code, notes, and snippets.

@ali-sheiba
Created June 29, 2016 05:59
Show Gist options
  • Save ali-sheiba/8896390204780ae75a049b31129174d8 to your computer and use it in GitHub Desktop.
Save ali-sheiba/8896390204780ae75a049b31129174d8 to your computer and use it in GitHub Desktop.
bashrc with git and rvm version in terminal
# Returns "*" if the current git branch is dirty.
function parse_git_dirty {
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "✘"
}
# print rvm version
function rvm_version {
[[ -z "${PWD//*\/var\/www\/*/}" ]] && echo "($(~/.rvm/bin/rvm-prompt v g))"
}
# Returns "|shashed:N" where N is the number of stashed states (if any).
function parse_git_stash {
local stash=`expr $(git stash list 2>/dev/null| wc -l)`
if [ "$stash" != "0" ]
then
echo "|stashed:$stash"
fi
}
# Get the current git branch name (if available)
git_prompt() {
local ref=$(git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3)
if [ "$ref" != "" ]
then
echo "($ref$(parse_git_stash))"
fi
}
if [ "$color_prompt" = yes ]; then
PS1='\[\033[01;34m\]\W\[\033[00m\]\[\033[01;32m\]$(git_prompt)\[\033[00m\]\[\033[00;33m\]$(rvm_version)\[\033[00m\]\[\033[01;31m\]$(parse_git_dirty)\[\033[00m\] $ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\ $ '
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment