#!/bin/bash function __rvm_parse-args { while [ $# -gt 0 ] ; do rvm_token="$1" ; shift case "$rvm_token" in install|uninstall|path|info|setup|version|srcdir|list|symlinks|reset|debug|reload|usage|help|implode|update) rvm_action=$rvm_token ;; use) rvm_action=$rvm_token if [ "$1" = "default" ] ; then rvm_ruby_interpreter="system" ; shift elif [ -z "$1" ] ; then rvm_ruby_interpreter="system" fi ;; ruby|jruby|ree|macruby|rbx|rubinius|default|all) rvm_ruby_interpreter="$rvm_token" rvm_action="${rvm_action:-use}" ;; gemdir) rvm_action=$rvm_token if [ "$1" = "system" ] ; then rvm_ruby_interpreter="system" ; shift fi if [ "$1" = "user" ] ; then rvm_ruby_interpreter="user" ; shift fi rvm_ruby_interpreter="${rvm_ruby_interpreter:-current}" ;; gemdup) rvm_action=$rvm_token if [ -z "$1" ] ; then rvm_ruby_interpreter="default" elif [ "$1" = "system" ] ; then rvm_ruby_interpreter=$1 ; shift elif [ "$1" = "default" ] ; then rvm_ruby_interpreter=$1 ; shift else rvm_ruby_interpreter=$1 ; shift rvm_ruby_version=$2 ; shift fi ;; do|rubydo|rakedo|gemdo) rvm_action=$rvm_token if [ "$rvm_action" = "do" ] ; then rvm_action="do" ; fi temp=$(echo $1 | awk '{print substr($1, 0, 1)}') if [ "$temp" != "-" ] ; then if [ ! -z "$(echo $temp | grep '[0-9]')" ] ; then rvm_ruby_version=$(echo "$1" | tr ',' ' ') ; shift else rvm_ruby_version=$1 ; shift fi else unset rvm_ruby_version fi unset rvm_ruby_interpreter ;; 1.8|1.8.0|1.8.1|1.8.2|1.8.3|1.8.4|1.8.5|1.8.6|1.8.7|1.9|1.9.1|1.9.2) rvm_ruby_interpreter="ruby" rvm_ruby_version="$rvm_token" rvm_action="${rvm_action:-use}" ;; 1.2.0|1.3.1) rvm_ruby_interpreter="jruby" rvm_ruby_version="$rvm_token" rvm_action="${rvm_action:-use}" ;; -v|--version) if [ -z "$1" ] ; then rvm_action="version" else rvm_ruby_version="$1" fi shift ;; -t|--tag) rvm_ruby_tag="$1"; rvm_action="${rvm_action:-use}" shift ;; -r|--rev) rvm_ruby_rev="$1"; rvm_action="${rvm_action:-use}" shift ;; -b|--branch) rvm_ruby_rev="$1"; rvm_action="${rvm_action:-use}" shift ;; -P|--prefix) rvm_prefix_path="$1" ; shift ;; -B|--bin) rvm_bin_path="$1" ; shift ;; -S|--source) rvm_source_path="$1" ; shift ;; -A|--archive) rvm_archives_path="$1" ; shift ;; -G|--gems) rvm_gem_path="$1" ; shift ;; -C|--configure) if [ ! -z "$1" ] ; then rvm_ruby_configure="$(echo $1 | tr ',' ' ')" shift else rvm_action="error" rvm_error_message="--configure *must* be followed by configure flags." break; fi ;; --re-configure) rvm_re_configure=1 ;; -M|--make) rvm_ruby_make="$1" ; shift ;; -I|--make-install) rvm_ruby_make_install="$1"; shift ;; -l|--level) rvm_ruby_patch_level="$1" ; shift ;; -n|--nice) rvm_niceness="$1" ; shift ;; -f|--file) rvm_ruby_args="$1" ; shift ;; -e|--execute) rvm_ruby_args="$@" rvm_parse_break=1 ;; -h|--help) rvm_action=help ; shift ;; -d|--default) rvm_set_default=1 ;; --head) rvm_ruby_rev="head" ;; --trace|--debug) rvm_debug=1 ;; --force) rvm_force=1 ;; --all) rvm_all=1 ; shift ;; -m|--gem-set) rvm_gem_set_name="$1" ; shift ;; --rm-gem-set) rvm_gem_set_name_rm="$1" ; shift ;; --dump) rvm_dump=1 ; shift ;; --load) rvm_load=1 if [ ! -z "$1" ] ; then rvm_load_file="$1" shift else rvm_action="error" rvm_error_message="--load must be followed by the .gemset file to load." break; fi shift ;; --latest) rvm_latest=1 ; shift ;; --jit) rvm_rubinius_jit="RBX_LLVM=1" ;; default|system) rvm_action="use" rvm_ruby_interpreter="system" ;; *) rvm_action="error" rvm_error_message="Unrecognized command line argument(s): '$rvm_token $@'" break; esac if [ ! -z "$rvm_parse_break" -o ! -z "$rvm_error_message" ] ; then unset rvm_parse_break; break; fi done if [ ! -z "$rvm_error_message" ] ; then popd 2> /dev/null ; return 1 ; fi if [ -z "$rvm_debug" ] ; then set +x ; else set -x ; fi } function rvm { __rvm_cleanup-variables __rvm_load-rvmrc __rvm_initialize __rvm_load-defaults __rvm_parse-args $@ case "$rvm_action" in install) __rvm_install-ruby ;; uninstall) __rvm_uninstall ;; use) __rvm_use ;; gemdir) __rvm_gem-dir ;; srcdir) __rvm_src-dir ;; gemdup) __rvm_gem-dup ;; list) __rvm_list ;; symlinks) __rvm_symlinks ;; version) __rvm_version ;; rubydo|rakedo|gemdo) if [ ! -z "$rvm_ruby_version" ] ; then rvm_ruby_versions=$(echo $rvm_ruby_version | tr ',' ' ') for rvm_ruby_version in $rvm_ruby_versions ; do temp=$(echo $rvm_ruby_version | awk '{print substr($1, 0, 1)}') if [ ! -z "$(echo $temp | grep '[0-9]')" ] ; then rvm_ruby_interpreter="ruby" else rvm_ruby_interpreter="$rvm_ruby_version" unset rvm_ruby_version fi unset temp __rvm_select $rvm_ruby_interpreter $rvm_ruby_version binary=`echo $rvm_action | sed 's/do$//'` rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_args" echo "$(basename $rvm_ruby_home/bin/$binary):" eval $rvm_command unset rvm_ruby_interpreter rvm_ruby_patch_level rvm_ruby_version rvm_ruby_package_name rvm_ruby_home rvm_ruby_irbrc rvm_ruby_binary done else # all rvm_ruby_versions=`/bin/ls $rvm_bin_path/ruby-*` for rvm_ruby_binary in $rvm_ruby_versions ; do if [ -x $rvm_ruby_binary ] ; then rvm_command="$rvm_ruby_binary $rvm_ruby_args" echo "$(basename $rvm_ruby_binary):" eval $rvm_command fi done fi ;; reset) __rvm_reset ;; # TODO: how can we use bin_path here for reload, default file? reload) source ~/.rvm/scripts/rvm ;; implode) __rvm_implode ;; update) if [ "$rvm_ruby_rev" = "head" ] ; then if [ -d $rvm_source_path/rvm/.git ] ; then cd $rvm_source_path/rvm/ && git pull origin master && ./scripts/rvm-install else cd $rvm_source_path && git clone git://github.com/wayneeseguin/rvm.git && cd rvm/ && ./scripts/rvm-install fi else # TODO: rvm_install_path: gem install rvm --no-rdoc --no-ri -q && rvm-install && source ~/.rvm/scripts/rvm fi ;; error) __rvm_log "fail" "$rvm_error_message ( see: rvm usage )" ; popd 2> /dev/null ; return 1; ;; info|debug) __rvm_version __rvm_info if [ "$rvm_action" = "debug" ] ; then __rvm_debug ; fi return 0 ;; usage|help) __rvm_usage ;; *) if [ ! -z "$rvm_action" ] ; then __rvm_log "fail" "unknown action '$rvm_action'" else __rvm_usage fi return 1 esac if [ "$rvm_debug" = "1" ] ; then set +x ; unset rvm_debug ; fi }