Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@taq
Created November 17, 2010 18:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save taq/703752 to your computer and use it in GitHub Desktop.
Save taq/703752 to your computer and use it in GitHub Desktop.
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