Skip to content

Instantly share code, notes, and snippets.

@careo
Created November 13, 2009 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save careo/233674 to your computer and use it in GitHub Desktop.
Save careo/233674 to your computer and use it in GitHub Desktop.
# NOTE 1: to use, you'll also need to place something like this in your precmd function:
# findrvm $PWD
#
# NOTE 2: It won't restore your rvm setting when you leave the directory. the function
# stops at the first .rvm it finds, so if you really want to always use a default ruby
# unless you tell it otherwise, put a .rvm somewhere outside all your projects.
#
# NOTE 3: also, for this to work in zsh you need the latest rvm from git that exports
# $rvm_ruby_string and $rvm_gem_set_name
#
# Stick this somewhere in your .profile, .zshrc, whatever:
# recursively search parent directories to see if there's a .rvm file
findrvm () {
if [[ -f "$1/.rvm" ]]; then
if [[ -z "$rvm_gem_set_name" ]] ; then
current_rvm_ruby="$rvm_ruby_string"
else
current_rvm_ruby="${rvm_ruby_string}%${rvm_gem_set_name}"
fi
dot_rvm=`cat $1/.rvm`
if [[ dot_rvm != current_rvm_ruby ]]; then #cat $1/.rvm
rvm `cat $1/.rvm`
fi
return
elif [[ $1 = / ]]; then
return
fi
current=`dirname $1`
findrvm $current
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment