Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Ruby version Bash function
# 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