scripts/utility in rvm-0.1.18 vs scripts/utility in rvm-0.1.19
- old
+ new
@@ -20,10 +20,12 @@
fi
fi
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
echo $(rvm_ruby_string="$rvm_ruby_args"; __rvm_select ; __rvm_use ; __rvm_environment_info)
@@ -121,12 +123,12 @@
return 1
else
results="$results $(__rvm_select ; echo $rvm_ruby_string)"
unset rvm_ruby_string
fi
- done
- echo $results
+ done
+ echo $results
unset results
return 0
}
# ZSH has 1 based array indexing, bash has 0 based.
@@ -177,11 +179,11 @@
# Unset both rvm variables as well as ruby-specific variables
# Preserve gemset if 'rvm_sticky' is set (persist gemset unless clear is explicitely called).
__rvm_cleanup_variables() {
__rvm_unset_ruby_variables
- if [[ "$rvm_sticky_flag" = "1" ]] ; then export rvm_gem_set_name ; else unset rvm_gem_set_name ; fi
+ 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_flag
}
# Unset ruby-specific variables
@@ -202,10 +204,25 @@
__rvm_load_rvmrc() {
if [[ -f /etc/rvmrc ]] ; then source /etc/rvmrc ; fi
if [[ -f "$HOME/.rvmrc" ]] ; then source "$HOME/.rvmrc" ; fi
}
+# 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"
+ unset code
+ cat $rvm_ruby_file >> "$rvm_tmp_path/$$.rb"
+ echo -e "\n end \nend\n" >> "$rvm_tmp_path/$$.rb"
+ rvm_ruby_args="$rvm_tmp_path/$$.rb"
+ rvm_benchmark_flag=1
+ action="ruby"
+ if [[ ! -z "$rvm_debug_flag" ]] ; then echo -e "$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.
__rvm_bin_scripts() {
for rvm_ruby_binary in $rvm_rubies_path/*/bin/ruby ; do
if [[ -x "$rvm_ruby_binary" ]] ; then
rvm_ruby_string=$(dirname "$rvm_ruby_binary" | xargs dirname | xargs basename)
@@ -242,11 +259,11 @@
# Load default ruby, if default is not set load system ruby.
__rvm_load_defaults() {
if [[ ! -s "$rvm_config_path/system" ]] ; then
for variable in RUBY_VERSION GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME ; do
eval value=\$${variable}
- if [[ -z "$value" ]] ; then
+ 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
@@ -313,11 +330,11 @@
$rvm_scripts_path/log "error" "remove '/' ?!... NO!"
else
if [[ -d "$rvm_path" ]] ; then
$rvm_scripts_path/log "info" "Hai! Removing $rvm_path"
rm -rf $rvm_path/
- $rvm_scripts_path/log "info" "$rvm_path has been removed."
+ echo "$rvm_path has been removed."
else
$rvm_scripts_path/log "info" "It appears that $rvm_path is already non existant."
fi
fi
break
@@ -347,19 +364,20 @@
# 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 [[ "rubies" = "$action" ]] ; then
+ elif [[ -z "$action" ]] || [[ "rubies" = "$action" ]] ; then
__rvm_list_rubies
elif [[ "strings" = "$action" ]] ; then
__rvm_list_strings
- else
+ else # help
echo -e "Usage: rvm list {known,default,rubies,strings}"
fi
}
__rvm_list_default() {
@@ -387,11 +405,11 @@
done < <(svn list http://svn.ruby-lang.org/repos/ruby/tags/ | awk '/^v1_[8|9]/')
echo -e "(ruby-)1.8.6(-p383)\n(ruby-)1.8.6-head\n(ruby-)1.8.7(-p248)\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"
echo -e "jruby-1.2.0\njruby-1.3.1\njruby(-1.4.0) # the default\njruby-head"
echo -e "rbx(-prc1) # 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(-22891)\nmaglev-head"
+ echo -e "maglev(-22907)\nmaglev-head"
echo -e "mput(-head) # shyouhei head, the default mput"
echo -e "ironruby-0.9.3 # (1.0 RC1)\nironruby-head"
if [[ "Darwin" = "$(uname)" ]] ; then
echo -e "macruby(-nightly) # the default macruby\nmacruby-head # Build from the macruby git repository"
fi
@@ -513,188 +531,10 @@
else
$rvm_scripts_path/log "info" "Carry on then..."
fi ; unset response
}
-# Perform an action using one of a selected ruby's specified binaries.
-__rvm_ruby_do() {
- __rvm_select
- __rvm_use
-
- binary="$(echo $rvm_action | sed 's#do$##')"
- if [[ -x "$rvm_ruby_home/bin/$binary" ]] ; then
- rm -f "$rvm_path/gems/cache"
- ln -nfs "$HOME/.gem/cache" "$rvm_path/gems/cache"
- binary="$rvm_ruby_home/bin/$binary"
- elif [[ -x "$rvm_ruby_global_gems_path/bin/$binary" ]] ; then
- binary="$rvm_ruby_global_gems_path/bin/$binary"
- elif [[ -x "$rvm_ruby_gem_home/bin/$binary" ]] ; then
- binary="$rvm_ruby_gem_home/bin/$binary"
- elif [[ "system" = "$rvm_ruby_string" ]] && [[ -x "$(which $binary)" ]] ; then
- binary="$(basename $(which $binary 2>/dev/null) 2>/dev/null)"
- else
- $rvm_scripts_path/log "warn" "'$binary not found for $rvm_ruby_string' either does not exist or is not executable? :("
- __rvm_unset_ruby_variables
- return 1
- fi
-
- if [[ ! -z "$rvm_ruby_mode" ]] ; then
- rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_mode"
- rvm_ruby_mode="--$(echo $rvm_ruby_mode | sed 's/^m//')"
- fi
-
- load_path="$(dirname $(which $binary 2>/dev/null) 2>/dev/null):$rvm_ruby_load_path"
- # TODO: the else case below should be run if $rvm_ruby_args =~ /\.rb$/
- if [[ "ruby" = "$(basename $binary)" ]] && [[ "$rvm_benchmark_flag" -ne 1 ]] ; then
- if $rvm_scripts_path/match "$rvm_ruby_args" "\.rb$" ; then
- if [[ -z "$prefix" ]] ; then prefix="-S" ; fi
- if ! $rvm_scripts_path/match "$rvm_ruby_args" "$prefix" ; then
- rvm_ruby_args="$prefix $rvm_ruby_args"
- fi
- fi
- rvm_command="$binary $rvm_ruby_mode $rvm_ruby_require -I$load_path $rvm_ruby_args"
- elif [[ "gem" = "$(basename $binary)" ]] && $rvm_scripts_path/match "$rvm_ruby_args" '^install' ; then
- #$rvm_scripts_path/gem install $rvm_ruby_args
- rvm_command="$rvm_scripts_path/gems $rvm_ruby_mode $rvm_ruby_args $rvm_gem_options"
- else
- rvm_command="$binary $rvm_ruby_mode $rvm_ruby_args"
- fi
-
- if [[ ! -z "$rvm_json_flag" ]] || [[ ! -z "$rvm_yaml_flag" ]] || [[ ! -z "$rvm_summary_flag" ]] ; then
- mkdir -p ./log/$rvm_ruby_string/
- touch ./log/$rvm_ruby_string/$rvm_action.log ./log/$rvm_ruby_string/$rvm_action.error.log
- eval "$rvm_command" >> ./log/$rvm_ruby_string/$rvm_action.log 2>> ./log/$rvm_ruby_string/$rvm_action.error.log
- else
- $rvm_scripts_path/log "info" "$rvm_ruby_string: $($rvm_ruby_home/bin/ruby -v $rvm_ruby_mode | tr "\n" ' ')"
- eval "$rvm_command"
- fi
- result=$?
-
- if [[ $result -eq 0 ]]; then
- eval "successes=(${successes[*]} $rvm_ruby_string)"
- else
- eval "errors=(${errors[*]} $rvm_ruby_string)"
- fi
- eval "rubies=(${rubies[*]} $rvm_ruby_string)"
- eval "statuses=(${statuses[*]} $result)"
- __rvm_unset_ruby_variables
-}
-
-# Loop over a set or all rvm installed rubies to perform some action.
-# Record the results and report based on CLI selections.
-__rvm_do() {
- __rvm_state
-
- rubies=() ; successes=() ; errors=() ; statuses=()
- # TODO: Extract the common functionality out of the if below
- if [[ ! -z "$rvm_ruby_string" ]] ; then
- unset rvm_ruby_interpreter rvm_ruby_version
- __rvm_ruby_do
- elif [[ ! -z "$rvm_ruby_version" ]] ;then
- for rvm_ruby_string in $(echo $rvm_ruby_version | tr ',' ' ') ; do
- __rvm_ruby_do
- done
- elif [[ ! -z "$rvm_ruby_interpreter" ]] ; then
- unset rvm_ruby_string rvm_ruby_version
- __rvm_ruby_do
- else # all
- for full_binary in $rvm_rubies_path/*/bin/ruby ; do
- if [[ -x "$full_binary" ]] ; then
- rvm_ruby_string="$(dirname $full_binary | xargs dirname | xargs basename)"
- __rvm_ruby_do
- fi
- done ; unset full_binary
- fi
-
- if [[ ! -z "$rvm_summary_flag" ]] ; then __rvm_summary ; fi
- if [[ ! -z "$rvm_yaml_flag" ]] ; then __rvm_yaml ; fi
- if [[ ! -z "$rvm_json_flag" ]] ; then __rvm_json ; fi
-
- __rvm_state
-
- $rvm_scripts_path/hook "after_do"
-
- return ${#errors[*]}
-}
-
-# Output the summary in a human readable format.
-__rvm_summary() {
- export successes errors statuses
- summary="\nSummary:\n\n"
- if [[ ${#successes[*]} -gt 0 ]] ; then
- summary="$summary \033[0;32m${#successes[*]} successful: $(echo "${successes[*]}" | sed 's# #, #g')\033[0m\n"
- fi
- if [[ ${#errors[*]} -gt 0 ]] ; then
- summary="$summary \033[0;31m${#errors[*]} errors: $(echo "${errors[*]}" | sed 's# #, #g')\033[0m\n"
- fi
- total=${#rubies[*]}
- if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi
- echo -e "$summary" | tee -a log/summary.log
- return ${#errors[*]}
-}
-
-# Output the summary in a yaml format.
-__rvm_yaml() {
- export successes errors statuses
- yaml="totals:\n rubies: ${#rubies[*]}\n successes: ${#successes[*]}\n errors: ${#errors[*]}\nsuccesses:"
- for var in ${successes[*]} ; do yaml="$yaml\n - $var" ; done
- yaml="$yaml\nerrors:"
- for var in ${errors[*]} ; do yaml="$yaml\n - $var" ; done
- yaml="$yaml\nrubies:"
- total=${#rubies[*]}
- if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi
- for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do
- if [[ ! -z "$rvm_debug_flag" ]] ; then
- $rvm_scripts_path/log "debug" "${rubies[$index]}: ${statuses[$index]}"
- fi
- yaml="$yaml\n \"${rubies[$index]}\": ${statuses[$index]}"
- done ; unset index array_start
- mkdir -p log
- echo -e "$yaml" | tee -a log/summary.yaml
-
- return ${#errors[*]}
-}
-
-# Output the summary in a json format.
-__rvm_json() {
- json="{"
- json="$json\n \"totals\": { \"rubies\": ${#rubies[*]}, \"successes\": ${#successes[*]}, \"errors\": ${#errors[*]}},"
- json="$json\n \"successful\": [ "$(echo ${successes[*]} | sed 's# #", "#g')" ],"
- json="$json\n \"errors\": [ "$(echo ${errors[*]} | sed 's# #", "#g')" ],"
- json="$json\n \"rubies\": {"
-
- total=${#rubies[*]}
- if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi
- for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do
- if [[ ! -z "$rvm_debug_flag" ]] ; then
- $rvm_scripts_path/log "debug" "${rubies[$index]}: ${statuses[$index]}"
- fi
- json="$json\n {\"${rubies[$index]}\": ${statuses[$index]}}"
- if (( $index + 1 < $total + $array_start )) ; then json="$json, " ; fi
- done ; unset index array_start
- json="$json\n }\n}"
-
- mkdir -p log
- echo -e "$json" | tee -a log/summary.json
-
- return ${#errors[*]}
-}
-
-# 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"
- unset code
- cat $rvm_ruby_file >> "$rvm_tmp_path/$$.rb"
- echo -e "\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
- __rvm_do
-}
-
# Create the irbrc for the currently selected ruby installation.
__rvm_irbrc() {
if [[ -d "$rvm_ruby_home" ]] && [[ ! -s "$rvm_ruby_irbrc" ]] ; then
cp $rvm_scripts_path/irbrc $rvm_ruby_irbrc
fi
@@ -775,31 +615,31 @@
# CXXFLAGS="-mmacosx-version-min="$(sw_vers -productVersion | awk -F'.' '{print $1"."$2}')" -isysroot /Developer/SDKs/$rvm_sdk " ; export CXXFLAGS
fi
fi
}
-# Select a gems(et) based on CLI set options and environment.
+# Select a gemset based on CLI set options and environment.
# This only sets 'rvm_ruby_gem_home'
-__rvm_gems_select() {
+__rvm_gemset_select() {
if ! which gem > /dev/null 2>&1 ; then return 0 ; fi
rvm_ruby_global_gems_path="$rvm_gems_path/$rvm_ruby_string%global"
- if [[ -z "$rvm_gem_set_name" ]] ; then
+ if [[ -z "$rvm_gemset_name" ]] ; then
# No longer defaulting to 'sticky' gem sets.
# Set 'rvm_sticky_flag=1' in ~/.rvmrc to enable.
if [[ ! -z "$rvm_sticky_flag" ]] ; then
if [[ ! -z "$GEM_HOME" ]] ; then
- rvm_gem_set_name=$(echo $GEM_HOME | xargs basename | awk -F'%' '{print $2}')
+ rvm_gemset_name=$(echo $GEM_HOME | xargs basename | awk -F'%' '{print $2}')
fi
if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
- rvm_gem_set_name=$(echo $rvm_ruby_gem_home | xargs basename | awk -F'%' '{print $2}')
+ rvm_gemset_name=$(echo $rvm_ruby_gem_home | xargs basename | awk -F'%' '{print $2}')
fi
fi
- if [[ ! -z "$rvm_gem_set_name" ]] && ! $rvm_scripts_path/match "$rvm_gem_set_name" "^[0-9]\.[0-9]" ; then
- rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gem_set_name"
+ if [[ ! -z "$rvm_gemset_name" ]] && ! $rvm_scripts_path/match "$rvm_gemset_name" "^[0-9]\.[0-9]" ; then
+ rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gemset_name"
else
if [[ ! -z "$rvm_ruby_string" ]] && [[ "$rvm_ruby_interpreter" != "system" ]] ; then
rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string"
elif [[ -z "$GEM_HOME" ]] && [[ ! -z "$(which gem 2>/dev/null)" ]] ; then
rvm_ruby_gem_home=$(gem env gemdir)
@@ -807,18 +647,18 @@
rvm_ruby_gem_home="$GEM_HOME"
else
unset rvm_ruby_gem_home
fi
fi
- if [[ -z "$rvm_gem_set_name" ]] ; then unset rvm_gem_set_name ; fi
+ if [[ -z "$rvm_gemset_name" ]] ; then unset rvm_gemset_name ; fi
else
- rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gem_set_name"
+ rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gemset_name"
fi
# If the gemset does not exist, then notify the user as such and abort the action.
- if [[ ! -d "$rvm_ruby_gem_home" ]] && [[ ! -z "$rvm_gem_set_name" ]] && [[ -z "$rvm_create_flag" ]]; then
- $rvm_scripts_path/log "error" "Gemset '$rvm_gem_set_name' does not exist, rvm gems create '$rvm_gem_set_name' first."
+ if [[ ! -d "$rvm_ruby_gem_home" ]] && [[ ! -z "$rvm_gemset_name" ]] && [[ -z "$rvm_create_flag" ]]; then
+ $rvm_scripts_path/log "error" "Gemset '$rvm_gemset_name' does not exist, rvm gems create '$rvm_gemset_name' first."
return 1
fi
rvm_ruby_gem_path="$rvm_ruby_gem_home:$rvm_ruby_global_gems_path"
@@ -830,15 +670,15 @@
fi
rmdir $rvm_path/gems/cache
fi
# Some sanity checking.
- if [[ ! -e "$HOME/.gem/cache" ]] ; then mkdir -p $HOME/.gem/cache ; fi
- chmod u+w "$HOME/.gem"
+ if [[ ! -e "$rvm_gems_cache_path" ]] ; then mkdir -p $rvm_gems_cache_path ; fi
+ chmod u+w "$rvm_gems_cache_path"
rm -f "$rvm_gems_path/cache"
- ln -nfs "$HOME/.gem/cache" "$rvm_gems_path/cache"
- chmod u+w "$HOME/.gem/cache"
+ ln -nfs "$rvm_gems_cache_path" "$rvm_gems_path/cache"
+ chmod u+w "$rvm_gems_cache_path"
# /TODO
# Careful not to nuke system gems cache.
if [[ ! -z "$rvm_ruby_gem_home" ]] && [[ ! -z "$(echo $rvm_ruby_gem_home | awk '/rvm/')" ]] ; then
# Ensure that the ruby gem home exists.
@@ -858,21 +698,21 @@
ln -nfs "$HOME/.gem/cache" "$rvm_ruby_gem_home/cache"
fi
fi ; export rvm_ruby_gem_path rvm_ruby_gem_home
}
-# Use a gems(et) specified by 'rvm_ruby_gem_home'
-__rvm_gems_use() {
+# Use a gemset specified by 'rvm_ruby_gem_home'
+__rvm_gemset_use() {
if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi
if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
if [[ ! -d "$rvm_ruby_gem_home" ]] ; then
- $rvm_scripts_path/log "error" "Gemset '$rvm_gem_set_name' does not exist, rvm gems create '$rvm_gem_set_name' first."
+ $rvm_scripts_path/log "error" "Gemset '$rvm_gemset_name' does not exist, rvm gems create '$rvm_gemset_name' first."
return 1
fi
if [[ "$rvm_interactive" = 1 ]] ; then
- $rvm_scripts_path/log "info" "gems(et) : ${rvm_gem_set_name:-default}"
+ $rvm_scripts_path/log "info" "gemset : ${rvm_gemset_name:-default}"
fi
export GEM_HOME="$rvm_ruby_gem_home"
export GEM_PATH="$rvm_ruby_gem_path"
export BUNDLE_PATH="$rvm_ruby_gem_home"