Created
November 17, 2010 18:13
-
-
Save taq/703752 to your computer and use it in GitHub Desktop.
Ruby version Bash function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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