Skip to content

Instantly share code, notes, and snippets.

@cevaris
Last active August 29, 2015 14:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cevaris/c07f7c075008e1ac38e6 to your computer and use it in GitHub Desktop.
Save cevaris/c07f7c075008e1ac38e6 to your computer and use it in GitHub Desktop.
RVM project init script which creates the appropriate .ruby-version .ruby-gemset files
#!/usr/bin/env zsh
# or #!/usr/bin/env bash
function rvm_init(){
RVM_VERSION=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
RVM_GEMSET=$(basename $(PWD))
for i in "$@"
do
case $i in
-g=*|--gemset=*)
RVM_GEMSET="${i#*=}"
;;
-r=*|--ruby=*)
RVM_VERSION="${i#*=}"
;;
*) # unknown option
;;
esac
done
print Gemset: $RVM_GEMSET
print Version: $RVM_VERSION
if ! type rvm > /dev/null 2>&1; then
print RVM is not installed
exit 1
fi
rvm --create --ruby-version $RVM_VERSION@$RVM_GEMSET
}
@cevaris
Copy link
Author

cevaris commented Apr 12, 2015

Installation

Copy and paste contents of rvm-init.sh into your ~/.zshrc or ~/.bashrc file

Usage

The following reuses the current Ruby version and directory name for the gemset as defaults
$ rvm_init

Custom ruby version and gemset name can be passed
$rvm_init --ruby=2.1.0 --gemset=custom_project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment