scripts/utility in rvm-0.1.32 vs scripts/utility in rvm-0.1.33
- old
+ new
@@ -1,7 +1,10 @@
#!/usr/bin/env bash
+# ZSH has 1 based array indexing, bash has 0 based.
+if [[ ! -z "$ZSH_VERSION" ]] ; then __shell_array_start=1 ; else __shell_array_start=0 ; fi
+
# Query the rvm key-value database for a specific key
# Allow overrides from user specifications in $rvm_config_path/user
__rvm_db() {
key=$1 ; variable=$2
if [[ -f "$rvm_config_path/user" ]] ; then
@@ -22,108 +25,14 @@
unset key value variable
}
is_a_function() { type $1 | head -n 1 | grep -q "function" ; }
-# Ouput rvm environment information.
-__rvm_info() {
- if [[ ! -z "$rvm_ruby_args" ]] ; then
- cat < <(rvm_ruby_string="$rvm_ruby_args"; __rvm_select ; __rvm_use ; __rvm_environment_info; echo -e "$environment_info")
- else
- __rvm_environment_info
- echo -e "$environment_info"
- fi
-}
-
-__rvm_environment_info() {
- environment_info="" ; full_version=""
- ruby=$(command -v ruby)
- if [[ $? -eq 0 ]] && [[ -x "$ruby" ]] ; then full_version="$($ruby -v)" ; fi
-
- environment_info="$environment_info\nsystem:\n uname: \"$(uname -a)\""
-
- if [[ ! -z "$ZSH_VERSION" ]] ; then
- environment_info="$environment_info\n shell: \"zsh\"\n version: \"$ZSH_VERSION\""
- fi
- if [[ ! -z "$BASH_VERSION" ]] ; then
- environment_info="$environment_info\n shell: \"bash\"\n version: \"$BASH_VERSION\""
- fi
- environment_info="$environment_info\n\nrvm:"
- environment_info="$environment_info\n type: \"$(head -n 1 < <(type rvm))\""
- environment_info="$environment_info\n version: \"$(__rvm_version | tr "\n" ' ' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')\""
- environment_info="$environment_info\n\nruby:"
- environment_info="$environment_info\n interpreter: \"$(echo "${full_version}" | awk '{print $1}')\""
- environment_info="$environment_info\n version: \"$(echo "${full_version}" | awk '{print $2}')\""
- environment_info="$environment_info\n date: \"$(echo "${full_version}" | sed 's/^.*(\([0-9]\{4\}\(-[0-9][0-9]\)\{2\}\).*$/\1/')\""
- environment_info="$environment_info\n platform: \"$(echo "${full_version}" | sed 's/^.*\[//' | sed 's/\].*$//')\""
- environment_info="$environment_info\n patchlevel: \"$(echo "${full_version}" | sed 's/^.*(//' | sed 's/).*$//')\""
- environment_info="$environment_info\n full_version: \"${full_version}\""
- environment_info="$environment_info\n\nhomes:"
- environment_info="$environment_info\n gem: \"${GEM_HOME:-'not set'}\""
- environment_info="$environment_info\n ruby: \"${MY_RUBY_HOME:-'not set'}\""
- environment_info="$environment_info\n\nbinaries:"
- environment_info="$environment_info\n ruby: \"$(command -v ruby)\""
- environment_info="$environment_info\n irb: \"$(command -v irb)\""
- environment_info="$environment_info\n gem: \"$(command -v gem)\""
- environment_info="$environment_info\n rake: \"$(command -v rake)\""
- environment_info="$environment_info\n\nenvironment:"
- environment_info="$environment_info\n GEM_HOME: \"$GEM_HOME\""
- environment_info="$environment_info\n GEM_PATH: \"$GEM_PATH\""
- environment_info="$environment_info\n BUNDLE_PATH: \"$BUNDLE_PATH\""
- environment_info="$environment_info\n MY_RUBY_HOME: \"$MY_RUBY_HOME\""
- environment_info="$environment_info\n IRBRC: \"$IRBRC\""
- environment_info="$environment_info\n RUBYOPT: \"$RUBYOPT\""
- environment_info="$environment_info\n gemset: \"$(echo $GEM_HOME | awk -F${rvm_gemset_separator:-'@'} '{print $2}')\"\n"
- if [[ ! -z "$MAGLEV_HOME" ]] ; then
- environment_info="$environment_info\n MAGLEV_HOME: \"$MAGLEV_HOME\""
- fi
- unset full_version
-}
-
-# Output debugging information that has been found useful to help people identify and resolve issues.
-__rvm_debug() {
- __rvm_version
- __rvm_environment_info
- $rvm_scripts_path/log "debug" "PATH:\n$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"$5}')"
- $rvm_scripts_path/log "debug" "uname -a: $(uname -a)"
- $rvm_scripts_path/log "debug" "permissions: $(\ls -la $rvm_path{,/rubies})"
-
- if [[ "Darwin" = "$(uname)" ]] ; then
- $rvm_scripts_path/log "debug" "uname -r: $(uname -r)"
- $rvm_scripts_path/log "debug" "uname -m: $(uname -m)"
- $rvm_scripts_path/log "debug" "sw_vers: $(sw_vers | tr "\n" ',')"
- $rvm_scripts_path/log "debug" "ARCHFLAGS: $ARCHFLAGS"
- $rvm_scripts_path/log "debug" "LDFLAGS: $LDFLAGS"
- $rvm_scripts_path/log "debug" "CFLAGS: $CFLAGS"
- $rvm_scripts_path/log "debug" "/Developer/SDKs/*:$(/usr/bin/basename -a /Developer/SDKs/* | tr "\n" ',')"
- fi
-
- for file_name in $(echo $rc_files) ; do
- if [[ -s "$file_name" ]] ; then
- $rvm_scripts_path/log "debug" "$file_name:\n$(grep 'rvm' $file_name 2>/dev/null)"
- fi
- done
-
- if [[ "root" = "$(whoami)" ]] ; then
- debug_files="$rvm_config_path/default $rvm_config_path/system $rvm_config_path/db /etc/rvmrc /etc/gemrc"
- else
- debug_files="$rvm_config_path/default $rvm_config_path/system $rvm_config_path/db $HOME/.rvmrc $HOME/.gemrc"
- fi
-
- for file_name in $(echo $debug_files); do
- if [[ -f "$file_name" ]] && [[ -s "$file_name" ]] ; then
- $rvm_scripts_path/log "debug" "$file_name \(filtered\):\n$(cat $file_name | awk '!/assword|_key/')\n"
- fi
- done
-
- $rvm_scripts_path/log "debug" "gem sources:\n$(gem sources | awk '/gems/')"
-}
-
__rvm_strings() {
unset results
for rvm_ruby_string in $(echo $rvm_ruby_args) ; do
- __rvm_ruby_string
+ #__rvm_ruby_string
if [[ $? -gt 0 ]] ; then
return 1
else
results="$results $(__rvm_select ; echo $rvm_ruby_string)"
fi
@@ -131,13 +40,10 @@
echo $results
unset results
return 0
}
-# ZSH has 1 based array indexing, bash has 0 based.
-if [[ ! -z "$ZSH_VERSION" ]] ; then __shell_array_start=1 ; else __shell_array_start=0 ; fi
-
# Push an item onto a given array.
__rvm_push() {
array=$1 ; shift ; item=$2
# TODO: allow loop over more arguments.
eval "index=\$((\${#${array}[*]} + $__shell_array_start))"
@@ -183,16 +89,16 @@
__rvm_cleanup_variables() {
__rvm_unset_ruby_variables
if [[ "$rvm_sticky_flag" = "1" ]] ; then export rvm_gemset_name ; else unset rvm_gemset_name ; fi
- unset rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_url rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_import_flag rvm_export_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_ruby_configure_flags rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_ruby_patch rvm_sticky_flagrvm_rvmrc_flag rvm_gems_flag
+ unset rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_url rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_import_flag rvm_export_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_ruby_configure_flags rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_ruby_patch rvm_sticky_flagrvm_rvmrc_flag rvm_gems_flag rvm_only_path_flag
}
# Unset ruby-specific variables
__rvm_unset_ruby_variables() {
- unset rvm_ruby_interpreter rvm_ruby_version rvm_url rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_ruby_binary rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_src_path rvm_ruby_repo_url rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_head_flag rvm_ruby_configure rvm_ruby_mode rvm_ruby_package_file rvm_ruby_package_name rvm_ruby_gem_path rvm_ruby_name rvm_ruby_alias
+ unset rvm_ruby_interpreter rvm_ruby_version rvm_url rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_release_version rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_ruby_binary rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_src_path rvm_ruby_repo_url rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_head_flag rvm_ruby_configure rvm_ruby_mode rvm_ruby_package_file rvm_ruby_package_name rvm_ruby_gem_path rvm_ruby_name rvm_ruby_alias
}
__rvm_set_rvmrc() {
if [[ "$HOME" != "$(pwd)" ]] ; then
if [[ "$rvm_create_flag" -eq 1 ]] ; then flags="--create " ; fi
@@ -224,18 +130,18 @@
}
# Wrap the specified ruby code file in a Benchmark.bmbm block and execute it.
__rvm_benchmark() {
code="require \"benchmark\" \n Benchmark.bmbm do |benchmark| \n benchmark.report(\"${rvm_ruby_file}\") do \n"
- echo -e "$code" > "$rvm_tmp_path/$$.rb"
+ printf "\n$code" > "$rvm_tmp_path/$$.rb"
unset code
cat $rvm_ruby_file >> "$rvm_tmp_path/$$.rb"
- echo -e "\n end \nend\n" >> "$rvm_tmp_path/$$.rb"
+ printf "\n end \nend\n" >> "$rvm_tmp_path/$$.rb"
rvm_ruby_args="$rvm_tmp_path/$$.rb"
rvm_benchmark_flag=1
rvm_action="ruby"
- if [[ ! -z "$rvm_debug_flag" ]] ; then echo -e "$rvm_tmp_path/$$.rb:\n$(cat $rvm_tmp_path/$$.rb)" ; fi
+ if [[ ! -z "$rvm_debug_flag" ]] ; then printf "\n$rvm_tmp_path/$$.rb:\n$(cat $rvm_tmp_path/$$.rb)" ; fi
$rvm_scripts_path/set $rvm_action $rvm_ruby_args
}
# Loop over the currently installed rubies and refresh their binscripts.
@@ -271,49 +177,10 @@
echo "$ruby_wrapper" > $rvm_bin_path/$rvm_ruby_package_name
unset ruby_wrapper
chmod +x $rvm_bin_path/$rvm_ruby_package_name
}
-# Load default ruby, if default is not set load system ruby.
-__rvm_load_defaults() {
- if [[ ! -s "$rvm_config_path/system" ]] && [[ "root" != "$(whoami)" ]] ; then
- for variable in RUBY_VERSION GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME ; do
- eval value=\$${variable}
- if [[ -z "${value/ /}" ]] ; then
- echo "unset ${variable}" >> $rvm_config_path/system
- else
- eval "export $variable"
- eval value=\$${variable}
- echo "${variable}='$value' ; export ${variable}" >> $rvm_config_path/system
- fi
- done
- fi
-
- __rvm_db "system_ruby" "rvm_system_ruby"
- if [[ ! -z "$rvm_system_ruby" ]] ; then
- rvm_system_ruby=$(command -v ruby)
- if [[ $? -ne 0 ]] ; then
- $rvm_scripts_path/log "info" "System ruby not found, no system default will be stored."
- else
- $rvm_scripts_path/db "$rvm_config_path/user" "system_ruby" "$rvm_system_ruby"
- # Now store system system & user gem paths
- if [[ ! -z "$(command -v gem)" ]] ; then
- __rvm_db "system_user_gem_path" "rvm_system_user_gem_path"
- if [[ -z "$rvm_system_user_gem_path" ]] ; then
- rvm_system_user_gem_path=$( rvm system ; gem env gemdir user; )
- $rvm_scripts_path/db "$rvm_config_path/user" "system_user_gem_path" "$rvm_system_user_gem_path"
- fi
- __rvm_db "system_gem_path" "rvm_system_gem_path"
- if [[ -z "$rvm_system_gem_path" ]] ; then
- rvm_system_gem_path=$( rvm system ; gem env gemdir; )
- $rvm_scripts_path/db "$rvm_config_path/user" "system_gem_path" "$rvm_system_gem_path"
- fi
- fi
- fi
- fi
-}
-
# Reset any rvm gathered information about the system and its state.
# rvm will refresh the stored information the next time it is called after reset.
__rvm_reset() {
PATH="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)"
PATH="$rvm_bin_path:$PATH" ; export PATH
@@ -369,114 +236,10 @@
else
echo "$rvm_ruby_src_path"
fi
}
-# Query for valid rvm ruby strings
-# This is meant to be used with scripting.
-__rvm_list_strings() {
- echo $(\ls $rvm_rubies_path)
-}
-
-# List all rvm installed rubies, default ruby and system ruby.
-# Display the rubies, indicate their architecture and indicate which is currently used.
-# This is not meant to be used with scripting. This is for interactive mode usage only.
-__rvm_list() {
- action="$(echo $rvm_ruby_args | awk '{print $1}')"
-
- if [[ "known" = "$action" ]] ; then
- __rvm_list_known
- elif [[ "default" = "$action" ]] ; then
- __rvm_list_default
- elif [[ -z "$action" ]] || [[ "rubies" = "$action" ]] ; then
- __rvm_list_rubies
- elif [[ "strings" = "$action" ]] ; then
- __rvm_list_strings
- else # help
- echo -e "Usage: rvm list {known,default,rubies,strings}"
- fi
-}
-
-__rvm_list_default() {
- strings="$(echo $rvm_ruby_args | awk '{print $2}')"
- if [[ "$strings" = "string" ]] ; then
- echo $(grep 'MY_RUBY_HOME' $rvm_config_path/default | awk -F"'" '{print $2}' | xargs basename)
- else
- if [[ -f "$rvm_config_path/default" ]] && [[ -s $rvm_config_path/default ]] ; then
- version=$(grep 'MY_RUBY_HOME' $rvm_config_path/default | awk -F"'" '{print $2}' | xargs basename)
- if [[ ! -z "$version" ]] ; then
- echo -e "\nDefault Ruby (for new shells)\n"
- string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- echo -e " $(tput setaf 2)$version$(tput sgr0) $string\n"
- fi ; unset version
- fi
- fi
-}
-
-__rvm_list_known() {
- while read -r tag
- do
- prefix="$(echo ${tag/\//} | sed 's#^v1_##' | awk -F'_' '{print "(ruby-)1."$1"."$2}' | sed 's#p$##')"
- echo "${prefix}-t${tag/\//}"
- unset prefix tag
- done < <(svn list http://svn.ruby-lang.org/repos/ruby/tags/ | awk '/^v1_[8|9]/')
- echo -e "(ruby-)1.8.6(-p399)\n(ruby-)1.8.6-head\n(ruby-)1.8.7(-p249)\n(ruby-)1.8.7-head\n(ruby-)1.9.1(-p243)\n(ruby-)1.9.1(-p376)\n(ruby-)1.9.1-head\n(ruby-)1.9.2-preview1\n(ruby-)1.9.2-head\nruby-head\n"
- echo -e "jruby-1.2.0\njruby-1.3.1\njruby-1.4.0\njruby(-1.5.0) # the default\njruby-head"
- echo -e "rbx(-prc5) # default\nrbx-head"
- echo -e "ree-1.8.6\nree(-1.8.7) # the default\nree-1.8.6-head\nree-1.8.7-head"
- echo -e "maglev(-23464)\nmaglev-head"
- echo -e "mput(-head) # shyouhei head, the default mput"
- echo -e "ironruby-0.9.3\nironruby-1.0-rc2\nironruby-head"
- if [[ "Darwin" = "$(uname)" ]] ; then
- echo -e "macruby(-nightly) # the default macruby\nmacruby-head # Build from the macruby git repository"
- fi
-}
-
-__rvm_list_rubies() {
- echo
- ruby=$(command -v ruby) ; current_ruby=""
- if [[ ! -z "$ruby" ]] && [[ ! -z "$(echo $ruby | awk '/rvm/')" ]] ; then
- current_ruby="$(echo $ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null)"
- fi
-
- echo -e "rvm Rubies\n"
- for version in $(\ls $rvm_rubies_path/ 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}') ; do
- if [[ ! -z "$(echo $version | awk '/^jruby-/')" ]] ; then
- string="[ $($rvm_rubies_path/$version/bin/ruby -v | awk '{print $NF}') ]"
- elif [[ ! -z "$(echo $version | awk '/^maglev-|^macruby-/')" ]] ; then
- string="[ x86_64 ]"
- else
- string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- fi
- if [[ "$version" = "$current_ruby" ]] ; then echo -n "=> " ; else echo -n " " ; fi
- echo -e "$(tput setaf 2)$version$(tput sgr0) $string"
- done ; unset version
-
- if [[ -f "$rvm_config_path/default" ]] && [[ -s $rvm_config_path/default ]] ; then
- version=$(grep 'MY_RUBY_HOME' $rvm_config_path/default | awk -F"'" '{print $2}' | xargs basename)
- if [[ ! -z "$version" ]] ; then
- echo -e "\nDefault Ruby (for new shells)\n"
- string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- echo -e " $(tput setaf 2)$version$(tput sgr0) $string"
- fi ; unset version
- fi
-
- system_ruby="$(rvm system ; command -v ruby)"
- if [[ ! -z "$system_ruby" ]] && [[ -x "$system_ruby" ]] ; then
- echo -e "\nSystem Ruby\n"
- system_version=$($system_ruby -v)
- binary=$(\ls -l "$system_ruby" | awk '{print $NF}') # Account for symbolic links.
- string="[ $(file $binary | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
-
- if [[ ! -z "$system_ruby" ]] && [[ "$current_ruby" = "$system_version" ]] ; then echo -n "=> " ; else echo -n " " ; fi
- echo -e "$(tput setaf 2)system$(tput sgr0) $string"
- fi
-
- unset current_ruby version selected system_ruby system_version string binary
- echo
-}
-
# Initialize rvm, ensuring that the path and directories are as expected.
__rvm_initialize() {
rvm_ruby_load_path="."
rvm_ruby_require=""
@@ -775,16 +538,54 @@
export ACLOCAL_FLAGS="-I $ACLOCAL_PATH"
export PKG_CONFIG_PATH="$rvm_usr_path/lib/pkgconfig:$PKG_CONFIG_PATH"
PATH="$rvm_usr_path/bin:$PATH"
}
+__rvm_environment_identifier() {
+ rvm_environment_identifier="${rvm_ruby_string}"
+ if [[ -n "${rvm_gemset_name}" ]]; then
+ rvm_environment_identifier="${rvm_environment_identifier}${rvm_gemset_separator}${rvm_gemset_name}"
+ fi
+ echo "$rvm_environment_identifier"
+ unset rvm_environment_identifier
+}
+
+__rvm_ensure_has_enviroment_files() {
+ local environment_identifier="$(__rvm_environment_identifier)"
+ file_name="${rvm_environments_path}/$environment_identifier"
+ if [[ ! -s "$file_name" ]] ; then
+ mkdir -p "${rvm_environments_path}"
+ echo "export PATH=\"${rvm_ruby_gem_home}/bin:${rvm_ruby_global_gems_path}/bin:${rvm_ruby_home}/bin:${rvm_bin_path}:\$PATH\"" > $file_name
+ for variable in RUBY_VERSION GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME IRBRC rvm_ruby_string rvm_gemset_name MAGLEV_HOME ; do
+ eval "export $variable"
+ eval value=\$${variable}
+ if [[ ! -z "$value" ]] ; then
+ echo "export ${variable}='$value'" >> $file_name
+ else
+ echo "unset ${variable}" >> $file_name
+ fi
+ done ; unset variable value
+ fi ; unset file_name
+ # Next, ensure we have default wrapper files. Also, prevent it from recursing.
+ if [[ -z "$rvm_creating_default_wrappers" ]]; then
+ rvm_creating_default_wrappers=1
+ directory_name="$rvm_wrappers_path/$environment_identifier"
+ if [[ ! -L "$directory_name" && ! -d "$directory_name" ]]; then
+ mkdir -p "$directory_name"
+ # Install the default wrappers.
+ $rvm_scripts_path/wrapper "$environment_identifier" &> /dev/null
+ fi
+ unset rvm_creating_default_wrappers directory_name
+ fi
+}
+
__rvm_Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything() {
for index in {1..750} ; do perl -e 'sleep 0.2'; echo -n '.' ; done ; printf "%d" 0x2A ; echo
}
__rvm_ultimate_question() {
- echo "I do not know the Ultimate Question, "
- echo "however I can help you build a more "
- echo "powerful Ruby which can compute the "
- echo "Ultimate Question."
+ printf "\nI do not know the Ultimate Question, "
+ printf "\nhowever I can help you build a more "
+ printf "\npowerful Ruby which can compute the "
+ printf "\nUltimate Question."
}