scripts/selector in rvm-1.0.5 vs scripts/selector in rvm-1.0.6

- old
+ new

@@ -215,11 +215,11 @@ rvm_ruby_release_version="${rvm_ruby_version/.*/}" rvm_ruby_major_version=${rvm_ruby_version%.*} ; rvm_ruby_major_version=${rvm_ruby_major_version#*.} rvm_ruby_minor_version="${rvm_ruby_version//*.}" fi - rvm_ruby_package_name="${rvm_ruby_package_name:-$(echo $rvm_ruby_string | sed -e 's/-n.*$//')}" + rvm_ruby_package_name="${rvm_ruby_package_name:-${rvm_ruby_string//-n*}}" rvm_ruby_home="$rvm_rubies_path/$rvm_ruby_string" rvm_ruby_log_path="$rvm_log_path/$rvm_ruby_string" rvm_ruby_repo_path="$rvm_repo_path/$rvm_ruby_string" rvm_ruby_src_path="$rvm_src_path/$rvm_ruby_string" rvm_ruby_binary="$rvm_ruby_home/bin/ruby" @@ -239,28 +239,23 @@ rvm_ruby_selected_flag=1 \mkdir -p "$rvm_ruby_log_path" - export rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_url rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_configure_flags rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_ruby_release_version rvm_ruby_major_version rvm_ruby_minor_version rvm_gemset_name rvm_gems_path rvm_ruby_gem_home rvm_path rvm_src_path rvm_bin_path rvm_ruby_binary rvm_ruby_home rvm_log_path rvm_ruby_log_path rvm_src_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string + export rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_url rvm_ruby_patch_level rvm_ruby_configure rvm_configure_flags rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_ruby_release_version rvm_ruby_major_version rvm_ruby_minor_version rvm_gemset_name rvm_gems_path rvm_ruby_gem_home rvm_path rvm_src_path rvm_bin_path rvm_ruby_binary rvm_ruby_home rvm_log_path rvm_ruby_log_path rvm_src_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string else rvm_ruby_interpreter="${rvm_ruby_interpreter:-system}" fi } __rvm_use() { - rvm_head_flag=${rvm_head_flag:-0} - rvm_default_flag=${rvm_default_flag:-0} - rvm_rvmrc_flag=${rvm_rvmrc_flag:-0} - rvm_verbose_flag=${rvm_verbose_flag:-0} - rvm_sticky_flag=${rvm_sticky_flag:-0} rvm_gemset_name="${rvm_gemset_name:-""}" rvm_ruby_gem_home="${rvm_ruby_gem_home:-""}" rvm_wrapper_name="${rvm_wrapper_name:-""}" rvm_ruby_alias="${rvm_ruby_alias:-""}" - local new_path="" + local new_path binary full_binary_path if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select "$@" ; fi if [[ -z "${rvm_ruby_interpreter:-""}" ]] ; then rvm_ruby_interpreter="system" ; fi @@ -280,11 +275,10 @@ source "$rvm_config_path/system" fi fi # Check binaries, remove under the condition they're symlinks. - local binary full_binary_path if [[ "$rvm_selfcontained" = "0" ]] ; then for binary in ruby gem irb ri rdoc rake erb testrb ; do full_binary_path="$rvm_bin_path/$binary" @@ -309,11 +303,11 @@ IRBRC=${IRBRC:-""} ; if [[ -z "$IRBRC" ]] ; then unset IRBRC ; fi if [[ ! -d "$MY_RUBY_HOME" ]] ; then "$rvm_scripts_path/log" "warn" "$rvm_ruby_interpreter $rvm_ruby_string is not installed." - if [[ $rvm_install_on_use_flag -eq 1 ]] ; then + if [[ ${rvm_install_on_use_flag:-0} -eq 1 ]] ; then "$rvm_scripts_path/manage" "install" "$rvm_ruby_string" else "$rvm_scripts_path/log" "info" "To install do: 'rvm install $rvm_ruby_string'" return 1 fi @@ -321,18 +315,21 @@ # Ensure the environment file for the selected ruby exists. __rvm_ensure_has_environment_files [[ ${rvm_verbose_flag:-0} -gt 0 ]] && \ - "$rvm_scripts_path/log" "info" "Using $(basename $GEM_HOME | \tr '-' ' ' | sed 's/'${rvm_gemset_separator}'/ with gemset /')" + "$rvm_scripts_path/log" "info" \ + "Using ${GEM_HOME/${rvm_gemset_separator:-'@'}/ with gemset }" new_path="$GEM_HOME/bin:$rvm_ruby_global_gems_path/bin:$MY_RUBY_HOME/bin:$rvm_bin_path:$(__rvm_remove_rvm_from_path ; printf "$PATH")" fi # Export ruby string and gem set me for extrenal scripts to take advantage of them. if [[ -n "${rvm_ruby_string:-""}" ]] ; then export rvm_ruby_string ; fi + if [[ -n "${rvm_gemset_name:-""}" ]] ; then export rvm_gemset_name ; fi + if [[ -n "$new_path" ]]; then export PATH="$new_path" unset new_path builtin hash -r fi @@ -340,22 +337,25 @@ if [[ ${rvm_rvmrc_flag:-0} -eq 1 ]] ; then __rvm_set_rvmrc ; fi local environment_id="$(__rvm_environment_identifier)" if [[ ${rvm_default_flag:-0} -eq 1 && "default" != "${rvm_ruby_interpreter:-""}" ]] ; then + if [[ "${rvm_selfcontained:-""}" = "0" ]] ; then # Sets up the default wrappers. "$rvm_scripts_path/wrapper" "$rvm_ruby_string" --no-prefix else "$rvm_scripts_path/wrapper" "$rvm_scripts_path" "default" fi + if [[ "system" = "$rvm_ruby_interpreter" ]] ; then "$rvm_scripts_path/alias" delete default &> /dev/null - \find "$rvm_bin_path" -name 'default_*' -maxdepth 1 -delete + \find "$rvm_bin_path" -name 'default_*' -maxdepth 0 -delete \rm -f "$rvm_config_path/default" \rm -f "$rvm_environments_path/default" \rm -rf "$rvm_wrappers_path/default" + else RUBY_VERSION="$("$rvm_ruby_home/bin/ruby" -v | sed 's#^\(.*\) (.*$#\1#')" export GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION "$rvm_scripts_path/alias" delete default &> /dev/null "$rvm_scripts_path/alias" create default "$environment_id" >& /dev/null @@ -430,107 +430,135 @@ ruby_string=${rvm_ruby_string/${rvm_gemset_separator}*/} __rvm_unset_ruby_variables - for string in $(printf "${ruby_string//-/ }") ; do + strings=(${ruby_string//-/ }) - if [[ "head" = "$string" ]] ; then + for string in "${strings[@]}" ; do + + # TODO: case... + + case "$string" in + head) + rvm_ruby_revision="head" rvm_ruby_patch_level="" ; rvm_ruby_revision="" ; rvm_ruby_tag="" export rvm_head_flag=1 + ;; - elif [[ "system" = "$string" ]] ; then + system) rvm_ruby_interpreter="system" rvm_ruby_patch_level="" ; rvm_ruby_tag="" ; rvm_head_flag=0 ; rvm_ruby_revision="" ; rvm_ruby_version="" ; rvm_gemset_name="" return 0 + ;; - elif [[ "nightly" = "$string" ]] ; then + nightly) rvm_ruby_version="nightly" rvm_nightly_flag=1 break + ;; - elif "$rvm_scripts_path/match" "$string" "^preview" ; then + preview*) rvm_ruby_patch_level="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^rc[0-9]" ; then + rc[[:digit:]]*) rvm_ruby_patch_level="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^[0-9]\.[0-9]" ; then + [[:digit:]]\.[[:digit:]]*) rvm_ruby_version="$string" - rvm_ruby_revision="" ; rvm_ruby_tag="" + rvm_ruby_revision="" + rvm_ruby_tag="" + ;; - elif "$rvm_scripts_path/match" "$string" "^p[0-9]" ; then + p[[:digit:]]*) rvm_ruby_patch_level="$string" + ;; - elif [[ -n "${rvm_ruby_version:-""}" ]] && "$rvm_scripts_path/match" "$string" "^[0-9][0-9]" ; then - if [[ "ree" = "${rvm_ruby_interpreter:-""}" ]] ; then - rvm_ruby_patch_level="$string" - rvm_ruby_revision="" + #elif [[ -n "${rvm_ruby_version:-""}" ]] && "$rvm_scripts_path/match" "$string" "^ + [[:digit:]][[:digit:]]*) - elif [[ "rbx" = "${rvm_ruby_interpreter:-""}" ]] ; then - rvm_ruby_patch_level="$string" + case "${rvm_ruby_interpreter:-""}" in + ree) + rvm_ruby_patch_level="$string" + rvm_ruby_revision="" + ;; - elif [[ "maglev" = "${rvm_ruby_interpreter:-""}" ]] ; then - rvm_ruby_version="$string" ; rvm_ruby_revision="" ; rvm_ruby_patch_level="" + rbx) + rvm_ruby_patch_level="$string" + ;; - else - rvm_ruby_revision="r$string" - fi + maglev) + rvm_ruby_version="$string" + rvm_ruby_revision="" + rvm_ruby_patch_level="" + ;; - elif "$rvm_scripts_path/match" "$string" "^r[0-9]" ; then + *) + rvm_ruby_revision="r$string" + ;; + esac + ;; + + r[[:digit:]]*) rvm_ruby_patch_level="" rvm_ruby_revision="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^s[0-9]" ; then + s[[:digit:]]*) rvm_ruby_revision="" rvm_ruby_sha="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^t[v0-9]" ; then + tv[[:digit:]]* | t[[:digit:]]*) rvm_ruby_patch_level="" ; rvm_ruby_revision="" rvm_ruby_tag="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^m[0-9]" ; then + m[[:digit:]]*) rvm_ruby_mode="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^u[a-z0-9]" ; then + u[[:alnum:]]*) rvm_ruby_patch_level="" ; rvm_ruby_revision="" ; rvm_ruby_tag="" ; rvm_ruby_patch="" rvm_ruby_user_tag="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^b[0-9][0-9]" ; then + b[[:digit:]][[:digit:]]*) rvm_ruby_bits="$string" + ;; - elif "$rvm_scripts_path/match" "$string" "^n" ; then + n*) rvm_ruby_name="${string/n/}" + ;; - elif [[ "ruby rbx jruby macruby ree rubinius maglev mput shyouhei ironruby " =~ "$string " ]] ; then - # NOTE: The space at the end of each of the above strings is *very* important. + ruby|rbx|jruby|macruby|ree|rubinius|maglev|mput|shyouhei|ironruby) rvm_ruby_interpreter="$string" + ;; - else - "$rvm_scripts_path/log" "error" "Unknown ruby string component: '$string'" + *) + "$rvm_scripts_path/log" "error" \ + "Unknown ruby string component: '$string'" return 1 - fi + ;; + esac done - # Unspecified interpreter if [[ -z "${rvm_ruby_interpreter:-""}" ]] ; then - - if "$rvm_scripts_path/match" "$rvm_ruby_version" "^1\.[8-9]" ; then - rvm_ruby_interpreter="ruby" - - elif "$rvm_scripts_path/match" "$rvm_ruby_version" "^0.5" ; then - rvm_ruby_interpreter="macruby" - - elif "$rvm_scripts_path/match" "$rvm_ruby_version" "^1.[2-4]" ; then - rvm_ruby_interpreter="jruby" - fi + # Detect interpreter based on version. + case "$rvm_ruby_version" in + 1.[8-9]*) rvm_ruby_interpreter="ruby" ;; + 0.[5-6]*) rvm_ruby_interpreter="macruby" ;; + 1.[2-7]*) rvm_ruby_interpreter="jruby" ;; + esac fi # Unspecified version rvm_ruby_version=${rvm_ruby_version:-""} - if [[ -z "${rvm_ruby_version:-""}" || ${rvm_head_flag:-0} -eq 0 ]] ; then + if [[ -z "${rvm_ruby_version:-""}" && ${rvm_head_flag:-0} -eq 0 ]] ; then rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "${rvm_ruby_interpreter}_version")"} fi if [[ -z "${rvm_ruby_version:-""}" ]] ; then rvm_ruby_string="${rvm_ruby_interpreter}" @@ -566,19 +594,19 @@ fi fi if [[ -n "${rvm_ruby_patch_level:-""}" ]] ; then - rvm_ruby_patch_level="$(echo $rvm_ruby_patch_level | sed 's#^pp#p#')" + rvm_ruby_patch_level="${rvm_ruby_patch_level/#pp/p}" rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_patch_level}" - if [[ "ree" = "${rvm_ruby_interpreter:-""}" ]] || [[ "rbx" = "${rvm_ruby_interpreter:-""}" ]] ; then - rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-p*#-#')" + if [[ "ree" = "${rvm_ruby_interpreter:-""}" || "rbx" = "${rvm_ruby_interpreter:-""}" ]] ; then + rvm_ruby_string="${rvm_ruby_string//-p*/-}" else - rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-pp#-p#')" - rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-prc#-rc#')" + rvm_ruby_string="${rvm_ruby_string//-pp/-p}" + rvm_ruby_string="${rvm_ruby_string//-prc/-rc}" fi fi fi if [[ -n "${rvm_ruby_name:-""}" ]] ; then @@ -587,18 +615,18 @@ } # Select a gemset based on CLI set options and environment. # This only sets 'rvm_ruby_gem_home' __rvm_gemset_select() { + command -v gem > /dev/null if [[ $? -gt 0 ]] ; then return 0 ; fi # Stop if no 'gem' command is available. rvm_ruby_gem_home=${rvm_ruby_gem_home:-""} rvm_gemset_name=${rvm_gemset_name:-""} + rvm_ruby_global_gems_path="$rvm_path/gems/${rvm_ruby_string:-""}${rvm_gemset_separator}global" - rvm_ruby_global_gems_path="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}global" - if [[ -z "${rvm_gemset_name:-""}" ]] ; then # No longer defaulting to 'sticky' gem sets. # Set 'rvm_sticky_flag=1' in ~/.rvmrc to enable. if [[ ${rvm_sticky_flag:-0} -eq 1 ]] ; then @@ -610,18 +638,19 @@ if [[ -n "${rvm_ruby_gem_home:-""}" ]] ; then rvm_gemset_name=$(echo $rvm_ruby_gem_home | xargs basename | awk -F${rvm_gemset_separator} '{print $2}') fi fi - if [[ -n "${rvm_gemset_name:-""}" ]] && ! "$rvm_scripts_path/match" "$rvm_gemset_name" "^[0-9]\.[0-9]" ; then + if ! echo "${rvm_gemset_name:-""}" | grep -q "^[[:digit:]]\.[[:digit:]]" ; then + rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}" else - if [[ -n "${rvm_ruby_string:-""}" ]] && [[ "${rvm_ruby_interpreter:-""}" != "system" ]] ; then + if [[ -n "${rvm_ruby_string:-""}" && "${rvm_ruby_interpreter:-""}" != "system" ]] ; then rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string" - elif [[ -z "${GEM_HOME:-""}" ]] && [[ -n "$(command -v gem)" ]] ; then + elif [[ -z "${GEM_HOME:-""}" && -n "$(command -v gem)" ]] ; then rvm_ruby_gem_home=$(gem env gemdir) elif [[ -n "${GEM_HOME:-""}" ]] ; then rvm_ruby_gem_home="$GEM_HOME" @@ -652,14 +681,18 @@ if [[ -z "${GEM_HOME:-""}" ]] ; then unset GEM_HOME ; fi # If the gemset does not exist, then notify the user as such and abort the action. if [[ -n "${rvm_gemset_name:-""}" && ! -d "$rvm_ruby_gem_home" ]] ; then + if [[ ${rvm_gemset_create_on_use_flag:-0} -ne 1 && ${rvm_create_flag:-0} -ne 1 && ${rvm_delete_flag:-0} -ne 1 ]] ; then + "$rvm_scripts_path/log" "error" "Gemset '$rvm_gemset_name' does not exist, rvm gemset create '$rvm_gemset_name' first." + return 1 fi + elif [[ ${rvm_delete_flag:-0} -eq 1 ]] ; then return 1 fi if [[ -z "${rvm_ruby_gem_home:-""}" && -n "${rvm_ruby_string:-""}" ]] ; then @@ -703,11 +736,11 @@ if [[ ${rvm_interactive_flag:-0} -gt 0 && ${rvm_verbose_flag:-1} -ne 0 ]] ; then "$rvm_scripts_path/log" "info" "Now using gemset '${rvm_gemset_name:-default}'" fi - rvm_ruby_gem_home="$(echo "${GEM_HOME:-""}" | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}${rvm_gemset_name}" + rvm_ruby_gem_home="${GEM_HOME//${rvm_gemset_separator}*}${rvm_gemset_separator}${rvm_gemset_name}" GEM_HOME="$rvm_ruby_gem_home" BUNDLE_PATH="$rvm_ruby_gem_home" GEM_PATH="$rvm_ruby_gem_home/bin:$(echo "$GEM_HOME" | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global/bin" export rvm_ruby_gem_home GEM_HOME BUNDLE_PATH GEM_PATH @@ -717,10 +750,10 @@ return 0 } __rvm_gemset_clear() { rvm_gemset_name="" ; shift # TODO: Is this shift necessary??? - rvm_ruby_gem_home="$(echo "${GEM_HOME:-""}" | sed "s#${rvm_gemset_separator:-'@'}.*\$##g")" + rvm_ruby_gem_home="${GEM_HOME//${rvm_gemset_separator:-'@'}*}" rvm_ruby_global_gems_path="$(echo "${GEM_HOME:-""}" | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global" GEM_HOME=$rvm_ruby_gem_home BUNDLE_PATH="$rvm_ruby_gem_home" GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin" export rvm_ruby_gem_home rvm_ruby_global_gems_path GEM_HOME BUNDLE_PATH GEM_PATH