scripts/utility in rvm-1.0.8 vs scripts/utility in rvm-1.0.9
- old
+ new
@@ -42,11 +42,11 @@
fi
fi
- unset rvm_ruby_strings rvm_head_flag rvm_prior_cc next_token result rvm_bin_path rvm_error_message rvm_gems_cache_path rvm_gems_path rvm_gemset_name rvm_interactive_flag rvm_man_path rvm_parse_break rvm_rc_files rvm_ruby_binary rvm_ruby_gem_home rvm_ruby_gem_path rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_log_path rvm_ruby_major_version rvm_ruby_minor_version rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_revision rvm_ruby_selected_flag rvm_ruby_string rvm_ruby_tag rvm_ruby_version rvm_selfcontained rvm_token
+ unset rvm_ruby_strings rvm_head_flag rvm_prior_cc next_token rvm_bin_path rvm_error_message rvm_gems_cache_path rvm_gems_path rvm_gemset_name rvm_interactive_flag rvm_man_path rvm_parse_break rvm_rc_files rvm_ruby_binary rvm_ruby_gem_home rvm_ruby_gem_path rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_log_path rvm_ruby_major_version rvm_ruby_minor_version rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_revision rvm_ruby_selected_flag rvm_ruby_string rvm_ruby_tag rvm_ruby_version rvm_selfcontained rvm_token
[[ ${rvm_dump_environment_flag:-0} -eq 1 ]] && __rvm_dump_environment
return 0
@@ -80,23 +80,23 @@
}
# Return a list of directories under a given base path.
# Derived from rvm_ruby_string.
__rvm_ruby_string_paths_under() {
- local path path_parts
+ local path part parts
- path="$1"
+ path="${1%/}" # Strip off any trailing slash
- path_parts="${rvm_ruby_string//-/ }"
+ parts=(${rvm_ruby_string//-/ }) # Strip white space.
- while true ; do
+ echo "$path"
- echo "$path/$path_parts" | sed -e 's# #/#g' -e 's#/$##g'
+ for part in "${parts[@]}" ; do
- [[ -z "$path_parts" ]] && break
+ path="$path/$part"
- path_parts="$(echo "$path_parts" | awk '{$NF=""; print}' | __rvm_strip)"
+ echo "$path"
done
return 0
}
@@ -206,118 +206,136 @@
return 0
}
# Clean all *duplicate* items out of the path. (keep first occurrence of each)
__rvm_clean_path() {
- PATH="$(echo $PATH | \tr -s ':' '\n' | awk '!($0 in a){a[$0];print}' | \tr -s '\n' ':' | sed 's#:$##')"
+ PATH="$(printf "$PATH" | \tr -s ':' '\n' | awk '!($0 in a){a[$0];print}' | \tr -s '\n' ':' | sed 's#:$##')"
+
export PATH
builtin hash -r
}
# Clean all rvm items out of the current working path.
__rvm_remove_rvm_from_path() {
- PATH="$(echo ${PATH} | awk -v RS=: -v ORS=: "/${rvm_path//\//\/}/ {next} {print}")"
+ PATH="$(printf "$PATH" | awk -v RS=: -v ORS=: "/${rvm_path//\//\/}/ {next} {print}" | sed -e 's#:$##')"
+
export PATH
builtin hash -r
}
# Run a specified command and log it.
__rvm_run() {
- local result log_file_name command message
+ local name log path command message
- log_file_name="${1:-""}"
+ name="${1:-""}"
command="${2:-""}"
message="${3:-""}"
- if [[ -n "$message" ]] ; then "$rvm_path/scripts/log" "info" "$message" ; fi
+ if [[ -n "$message" ]] ; then
+ "$rvm_path/scripts/log" "info" "$message"
+ fi
if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then
- "$rvm_path/scripts/log" "debug" "Executing: $command"
+ "$rvm_path/scripts/log" "debug" \
+ "Executing: $command"
fi
- \mkdir -p "$(dirname "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log")"
+ path="${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string"
- \touch "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log" \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log" # for zsh :(
+ log="$path/$name.log"
- echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command" | \
- \tee "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log" >> \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log"
+ if [[ ! -d "$path" ]] ; then
+ \mkdir -p "$path"
+ fi
- (
- if [[ -z "${rvm_niceness:-""}" || "0" = "${rvm_niceness:-""}" ]] ; then
- eval "$command" >> \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log" 2>> \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log"
- else
- eval "nice -n $rvm_niceness $command" >> \
- ${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log 2>> \
- ${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log
- fi
- )
- local result=$?
+ \touch "$log" "${log/%.log/.error.log}" # for zsh :(
+ printf "[$(date +'%Y-%m-%d %H:%M:%S')] $command" | \
+ \tee "$log" \
+ >> "${log/%log/error.log}"
+
+ if [[ ${rvm_niceness:-0} -gt 0 ]] ; then
+ command="nice -n $rvm_niceness $command"
+ fi
+
+ eval "$command" \
+ >> "$log" \
+ 2>> "${log/%log/error.log}"
+
+ result=$?
+
if [[ $result -gt 0 ]] ; then
"$rvm_path/scripts/log" "error" \
- "Error running '$command', please check ${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name*.log"
+ "Error running '$command', please check ${log/%log/error.log}"
fi
- return $result
+ return ${result:-0}
}
# Runs a command in a given env.
__rvm_run_with_env() {
- local result log_file_name env_name comand message
+ local name environment command message log path
- log_file_name="${1:-""}"
- env_name="${2:-""}"
+ name="${1:-""}"
+ environment="${2:-""}"
command="${3:-""}"
message="${4:-""}"
- if [[ -z "$env_name" ]]; then env_name="$(__rvm_environment_identifier)"; fi
+ if [[ -z "$environment" ]] ; then
+ environment="$(__rvm_environment_identifier)"
+ fi
- if [[ -n "$message" ]] ; then "$rvm_path/scripts/log" "info" "$message" ; fi
+ if [[ -n "$message" ]] ; then
+ "$rvm_path/scripts/log" "info" "$message"
+ fi
if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then
- "$rvm_path/scripts/log" "debug" "Executing: $command in environment "$env_name""
+ "$rvm_path/scripts/log" "debug" "Executing: $command in environment "$environment""
fi
- \mkdir -p "$(dirname "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log")"
+ path="${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string"
- \touch \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log" \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log" # for zsh :(
+ log="$path/$name.log"
- echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command # under $env_name" | \
- tee "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log" >> \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log"
+ if [[ ! -d "$path" ]] ; then
+ \mkdir -p "$path"
+ fi
+ \touch "$log" "${log/%.log/.error.log}" # for zsh :(
+
+ printf "[$(date +'%Y-%m-%d %H:%M:%S')] $command # under $environment\n" \
+ | tee "${log}" \
+ >> "${log/%log/error.log}"
+
+ if [[ ${rvm_niceness:-0} -gt 0 ]] ; then
+ command="nice -n $rvm_niceness $command"
+ fi
+
(
- if [[ -z "${rvm_niceness:-""}" || $rvm_niceness -eq 0 ]] ; then
- eval "__rvm_with_env '$env_name' '$command'" >> \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log" 2>> \
- "${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log"
- else
- eval "nice -n $rvm_niceness __rvm_with_env '$env_name' '$command'" >> \
- ${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.log 2>> \
- ${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name.error.log
- fi
+ rvm_ruby_string="$environment"
+
+ __rvm_use
+
+ eval "$command" \
+ >> "${log}" \
+ 2>> "${log/%log/error.log}"
)
+
result=$?
if [[ $result -gt 0 ]] ; then
"$rvm_path/scripts/log" "error" \
- "Error running '$command' under $env_name, please check ${rvm_log_path:-"$rvm_path/log"}/$rvm_ruby_string/$log_file_name*.log"
+ "Error running '$command' under $env_name, please check ${log/%log/error.log}"
fi
- return $result
+ return ${result:-0}
}
__rvm_nuke_rvm_variables() {
unset rvm_head_flag $(env | awk -F= '/^rvm_/{print $1" "}')
}
@@ -337,24 +355,10 @@
if [[ ${rvm_sticky_flag:-0} -eq 1 ]] ; then export rvm_gemset_name ; else unset rvm_gemset_name ; fi
unset rvm_action rvm_irbrc_file rvm_command rvm_error_message 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_configure_flags rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_sticky_flag rvm_rvmrc_flag rvm_gems_flag rvm_only_path_flag rvm_docs_flag rvm_ruby_aliases rvm_patch_names rvm_clang_flag rvm_install_arguments rvm_dump_environment_flag rvm_ruby_alias
}
-# Usage: __rvm_with_env 'env-name' 'command'
-__rvm_with_env() {
- local environment_id command
-
- environment_id="$1"
- command="$2"
-
- (
- rvm use "$environment_id"
-
- eval "$command"
- )
-}
-
# Returns the first 1.8.7-compatible (partly) ruby for use
# with things like rbx etc which require a ruby be installed.
__rvm_18_compat_ruby() {
local rubies ruby_name
@@ -468,11 +472,11 @@
}
# Wrap the specified ruby code file in a Benchmark.bmbm block and execute it.
__rvm_benchmark() {
- local result old_rvm_ruby_string
+ local old_rvm_ruby_string
code="require \"benchmark\" \n Benchmark.bmbm do |benchmark| \n benchmark.report(\"${rvm_ruby_file}\") do \n"
printf "\n$code" > "${rvm_tmp_path:-"$rvm_path/tmp"}/$$.rb"
@@ -507,11 +511,11 @@
"$rvm_path/scripts/set" "$rvm_action" $rvm_ruby_args ; result=$?
# Restore the state pre-sets.
[[ -n "$old_rvm_ruby_string" ]] && rvm_ruby_string=$old_rvm_ruby_string
- return $result
+ return ${result:-0}
}
# Loop over the currently installed rubies and refresh their binscripts.
__rvm_bin_scripts() {
@@ -663,10 +667,10 @@
}
# Output the current ruby's rvm source path.
__rvm_source_dir() {
- if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi
+ if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select ; fi
if [[ -z "$rvm_ruby_src_path" ]] ; then
"$rvm_path/scripts/log" "fail" \
"No source directory exists for the default implementation."