Skip to content

Instantly share code, notes, and snippets.

@ches
Created February 20, 2011 16:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ches/836069 to your computer and use it in GitHub Desktop.
Save ches/836069 to your computer and use it in GitHub Desktop.
An example of a bash prompt showing RVM Ruby version and active gemset
RED="\[\033[01;31m\]"
GREEN="\[\033[01;32m\]"
COLOR_NONE="\[\033[0m\]"
function ruby_version {
if [[ -f ~/.rvm/bin/rvm-prompt ]]; then
local system=$(~/.rvm/bin/rvm-prompt s)
local interp=$(~/.rvm/bin/rvm-prompt i)
if [[ ! -n $system ]]; then
# Don't show interpreter if it's just MRI
case $interp in
ruby) echo " ${RED}♦ $(~/.rvm/bin/rvm-prompt v g)${COLOR_NONE}" ;;
*) echo " ${RED}♦ $(~/.rvm/bin/rvm-prompt i v g)${COLOR_NONE}" ;;
esac
fi
fi
}
function prompt_func {
previous_return_value=$?;
prompt="${GREEN}\w${COLOR_NONE}$(ruby_version)\n[\u@\h]"
if test $previous_return_value -eq 0
then
PS1="\n${prompt}\$ "
else
PS1="\n${prompt}${RED}\$${COLOR_NONE} "
fi
}
export PROMPT_COMMAND=prompt_func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment