Skip to content

Instantly share code, notes, and snippets.

@cppforlife
Created July 28, 2010 09:25
Show Gist options
  • Save cppforlife/493849 to your computer and use it in GitHub Desktop.
Save cppforlife/493849 to your computer and use it in GitHub Desktop.
COLOR_RED="\[\e[31;40m\]"
COLOR_GREEN="\[\e[32;40m\]"
COLOR_CYAN="\[\e[36;40m\]"
COLOR_RESET="\[\e[0m\]"
function git_branch_name {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ("${ref#refs/heads/}")"
# possible to use __git_ps1 here
}
function git_branch_color {
if [[ $(git status 2> /dev/null | grep -c :) == 0 ]]
then echo "${COLOR_GREEN}"
else echo "${COLOR_RED}"
fi
}
function rvm_current_env {
if [[ $(gem env gemdir) =~ \.rvm/gems/(.*) ]]
then echo " (${BASH_REMATCH[1]})"
fi
}
function prompt_title {
PS1="\w${COLOR_CYAN}$(rvm_current_env)$(git_branch_color)$(git_branch_name)${COLOR_RESET} \$ "
}
PROMPT_COMMAND=prompt_title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment