Skip to content

Instantly share code, notes, and snippets.

@aribeiro
Forked from taq/ruby-version.bash
Created November 18, 2010 11:24
Show Gist options
  • Save aribeiro/704873 to your computer and use it in GitHub Desktop.
Save aribeiro/704873 to your computer and use it in GitHub Desktop.
# First parameter is a bash printf formatting string
# From second till fifth parameter, rvm-prompt format parameters
__ruby_ps1 () {
if [ ! -f ./Rakefile ] &&
[ "$(find -maxdepth 1 -name '*.rb' | head -n1)" == "" ]; then
exit 1
fi
if [ -f ~/.rvm/bin/rvm-prompt ]; then
rst=$(~/.rvm/bin/rvm-prompt $2 $3 $4 $5)
fi
if [ -z "$rst" ]; then
rst=$(ruby -v | cut -f2 -d' ')
fi
fmt="%s"
if [ -n "$1" ]; then
fmt="$1"
fi
if [ -n "$rst" ]; then
printf "$fmt" "${rst}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment