scripts/utility in rvm-1.0.4 vs scripts/utility in rvm-1.0.5

- old
+ new

@@ -180,36 +180,37 @@ builtin hash -r } # Run a specified command and log it. __rvm_run() { - local log_file_name="$1" - local command="$2" - local message="$3" + local log_file_name="${1:-""}" + local command="${2:-""}" + local message="${3:-""}" if [[ -z "$rvm_ruby_log_path" ]] ; then rvm_ruby_log_path="$rvm_log_path" ; fi if [[ -n "$message" ]] ; then "$rvm_scripts_path/log" "info" "$message" ; fi - if [[ -n "$rvm_debug_flag" ]] ; then + if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "Executing: $command" fi \mkdir -p "$(dirname "$rvm_ruby_log_path/$log_file_name.log")" \touch "$rvm_ruby_log_path/$log_file_name.log" "$rvm_ruby_log_path/$log_file_name.error.log" # for zsh :( echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command" | \tee "$rvm_ruby_log_path/$log_file_name.log" >> "$rvm_ruby_log_path/$log_file_name.error.log" - if [[ -z "$rvm_niceness" ]] || [[ "0" = "$rvm_niceness" ]] ; then - eval "$command" >> "$rvm_ruby_log_path/$log_file_name.log" 2>> "$rvm_ruby_log_path/$log_file_name.error.log" - else - eval "nice -n $rvm_niceness $command" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log - fi ; local result=$? - - if [[ $result -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name*.log" ; __rvm_pushpop + ( + if [[ -z "${rvm_niceness:-""}" || "0" = "${rvm_niceness:-""}" ]] ; then + eval "$command" >> "$rvm_ruby_log_path/$log_file_name.log" 2>> "$rvm_ruby_log_path/$log_file_name.error.log" + else + eval "nice -n $rvm_niceness $command" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log + fi + ) + local result=$? ; if [[ $result -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name*.log" fi return $result } @@ -224,48 +225,54 @@ if [[ -z "$rvm_ruby_log_path" ]] ; then rvm_ruby_log_path="$rvm_log_path" ; fi if [[ -n "$message" ]] ; then "$rvm_scripts_path/log" "info" "$message" ; fi - if [[ -n "$rvm_debug_flag" ]] ; then + if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "Executing: $command in environment "$env_name"" fi \mkdir -p "$(dirname "$rvm_ruby_log_path/$log_file_name.log")" \touch "$rvm_ruby_log_path/$log_file_name.log" "$rvm_ruby_log_path/$log_file_name.error.log" # for zsh :( echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command # under $env_name" | tee "$rvm_ruby_log_path/$log_file_name.log" >> "$rvm_ruby_log_path/$log_file_name.error.log" - if [[ -z "$rvm_niceness" || "0" = "$rvm_niceness" ]] ; then - eval "__rvm_with_env '$env_name' '$command'" >> "$rvm_ruby_log_path/$log_file_name.log" 2>> "$rvm_ruby_log_path/$log_file_name.error.log" - else - eval "nice -n $rvm_niceness __rvm_with_env '$env_name' '$command'" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log - fi ; result=$? - - if [[ $result -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "Error running '$command' under $env_name, please check $rvm_ruby_log_path/$log_file_name*.log" ; __rvm_pushpop + ( + if [[ -z "${rvm_niceness:-""}" || $rvm_niceness -eq 0 ]] ; then + eval "__rvm_with_env '$env_name' '$command'" >> "$rvm_ruby_log_path/$log_file_name.log" 2>> "$rvm_ruby_log_path/$log_file_name.error.log" + else + eval "nice -n $rvm_niceness __rvm_with_env '$env_name' '$command'" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log + fi + ) + result=$? ; if [[ $result -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" "Error running '$command' under $env_name, please check $rvm_ruby_log_path/$log_file_name*.log" fi return $result } -# Unset both rvm variables as well as ruby-specific variables +__rvm_nuke_rvm_variables() { + unset rvm_head_flag $(env | awk -F= '/^rvm_/{print $1" "}') +} + +# Unset ruby-specific variables +__rvm_unset_ruby_variables() { + unset rvm_head_flag $(env | awk -F= '/^rvm_ruby_/{printf $1" "}') +} + +# TODO: Should be able to... +# 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_cleanse_variables() { __rvm_unset_ruby_variables 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_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_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 + 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_ruby_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 } -# 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_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_strings rvm_ruby_repo_path -} - # Usage: __rvm_with_env 'env-name' 'command' __rvm_with_env() { local environment_id="$1" command="$2" ( rvm use "$environment_id" ; eval "$command" ) } @@ -299,17 +306,10 @@ fi return 0 } -__rvm_inherit_trace_flag() { - if [[ -n "$rvm_trace_flag" ]]; then - set -x ; export rvm_trace_flag - fi - return 0 -} - # Cleans up temp folders for a given prefix, # typically the current process id. __rvm_cleanup_temp_for() { local prefix="$1" @@ -320,18 +320,15 @@ fi exit } -__rvm_cleanup_temp_on_exit() { - trap "__rvm_cleanup_temp_for '$$'" 0 1 2 3 15 -} - __rvm_set_rvmrc() { if [[ "$HOME" != "$PWD" ]] ; then - if [[ ${rvm_verbose_flag:-0} -eq 1 ]] ; then flags="use " ; fi + if [[ ${rvm_verbose_flag:-0} -gt 0 ]] ; then flags="use " ; fi + if [[ -s .rvmrc ]] ; then mv .rvmrc .rvmrc.$(date +%m.%d.%Y-%H:%M:%S) "$rvm_scripts_path/log" "warning" ".rvmrc is not empty, moving aside to preserve." fi @@ -371,11 +368,11 @@ cat $rvm_ruby_file >> "$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 [[ -n "$rvm_debug_flag" ]] ; then printf "\n$rvm_tmp_path/$$.rb:\n$(cat $rvm_tmp_path/$$.rb)" ; fi + if [[ ${rvm_debug_flag:0} -gt 0 ]] ; then printf "\n$rvm_tmp_path/$$.rb:\n$(cat $rvm_tmp_path/$$.rb)" ; fi # Override ruby string stuff, pass through. local old_rvm_ruby_string=$rvm_ruby_string # TODO: We can likely do this in a subshell in order to preserve the original environment? unset rvm_ruby_string export rvm_ruby_strings @@ -500,55 +497,51 @@ return 0 } # Update rubygems or binscripts based on CLI selection. __rvm_update() { - __rvm_pushpop $rvm_path + ( + builtin cd "$rvm_path" - if [[ ${rvm_head_flag:-0} -eq 1 || ${rvm_self_flag:-0} -eq 1 || "update" = "${rvm_action:-""}" || ${rvm_update_flag:-0} -eq 1 ]] ; then - __rvm_version - __rvm_update_rvm - fi + if [[ ${rvm_head_flag:-0} -eq 1 || ${rvm_self_flag:-0} -eq 1 || "update" = "${rvm_action:-""}" || ${rvm_update_flag:-0} -eq 1 ]] ; then + __rvm_version + __rvm_update_rvm + fi - [[ ${rvm_bin_flag:-0} -eq 1 ]] && __rvm_bin_scripts + [[ ${rvm_bin_flag:-0} -eq 1 ]] && __rvm_bin_scripts - # Update to the latest rubygems. - [[ ${rvm_rubygems_flag:-0} -eq 1 ]] && "$rvm_scripts_path/rubygems" current + # Update to the latest rubygems. + [[ ${rvm_rubygems_flag:-0} -eq 1 ]] && "$rvm_scripts_path/rubygems" current + ) unset rvm_update_flag rvm_action rvm_self_flag rvm_ruby_revision rvm_bin_flag rvm_rubygems_flag - - __rvm_pushpop - return 0 } # Update rvm using rubygems # If --head was specified, update from git repository master branch. __rvm_update_rvm() { - \mkdir -p "$rvm_src_path" - - __rvm_pushpop "$rvm_src_path" - - if [[ ${rvm_head_flag:-0} -eq 1 ]] ; then - if [[ -d "$rvm_src_path/rvm/.git" ]] ; then - builtin cd "$rvm_src_path/rvm/" && git pull origin master && ./scripts/install + ( + builtin cd "$rvm_src_path" + if [[ ${rvm_head_flag:-0} -eq 1 ]] ; then + if [[ -d "$rvm_src_path/rvm/.git" ]] ; then + builtin cd "$rvm_src_path/rvm/" && git pull origin master && ./scripts/install + else + builtin cd "$rvm_src_path" && ( git clone --depth 1 git://github.com/wayneeseguin/rvm.git || git clone http://github.com/wayneeseguin/rvm.git ) && builtin cd rvm/ && ./scripts/install + fi else - builtin cd "$rvm_src_path" && ( git clone --depth 1 git://github.com/wayneeseguin/rvm.git || git clone http://github.com/wayneeseguin/rvm.git ) && builtin cd rvm/ && ./scripts/install - fi - else - stable_version="$(curl -s http://rvm.beginrescueend.com/releases/stable-version.txt)" + stable_version="$(curl -s http://rvm.beginrescueend.com/releases/stable-version.txt)" - __rvm_run "fetch" "$rvm_scripts_path/fetch 'http://rvm.beginrescueend.com/releases/rvm-${stable_version}.tar.gz'" "fetching rvm-${stable_version}.tar.gz" + __rvm_run "fetch" "$rvm_scripts_path/fetch 'http://rvm.beginrescueend.com/releases/rvm-${stable_version}.tar.gz'" "fetching rvm-${stable_version}.tar.gz" - __rvm_run "extract" "gunzip < \"$rvm_archives_path/rvm-${stable_version}.tar.gz\" | tar xf - -C $rvm_src_path" "Extracting rvm-${stable_version}.tar.gz ..." + __rvm_run "extract" "gunzip < \"$rvm_archives_path/rvm-${stable_version}.tar.gz\" | tar xf - -C $rvm_src_path" "Extracting rvm-${stable_version}.tar.gz ..." - __rvm_run "install" "builtin cd $rvm_src_path/rvm-${stable_version}/ ; ./install" "Installing rvm-${stable_version}..." - fi + __rvm_run "install" "builtin cd $rvm_src_path/rvm-${stable_version}/ ; ./install" "Installing rvm-${stable_version}..." + fi + ) - __rvm_pushpop - rvm_hook="after_update" ; source "$rvm_scripts_path/hook" return 0 } @@ -590,21 +583,10 @@ \cp "$rvm_scripts_path/irbrc" "$rvm_ruby_irbrc" fi return $? } -# Push or Pop a directory based on zero or one directory argument provided. -__rvm_pushpop() { - if [[ -z "$1" ]] ; then - popd > /dev/null 2>&1 - else - pushd "$1" > /dev/null 2>&1 - fi - - return $? -} - # Save or restore the rvm's state. This is a toggle action. # Meant for use before and after an operation that might reset the currently selected ruby. __rvm_state() { if [[ -z "$rvm_state" ]] ; then rvm_state="$(__rvm_environment_identifier)" @@ -659,24 +641,26 @@ # Set the build & host type if [[ "Power Macintosh" = "$(sysctl -n hw.machine)" ]] ; then : # Do nothing ? elif [[ "$(sysctl -n hw.cpu64bit_capable)" = 1 || "$(sysctl -n hw.optional.x86_64)" = 1 ]] ; then # 64 bit capable - if [[ "-arch x86_64" = "$rvm_archflags" ]] ; then + if [[ "-arch x86_64" = "${rvm_archflags:-""}" ]] ; then rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=x86_64-apple-darwin$(uname -r) --host=x86_64-apple-darwin$(uname -r)" - elif [[ "-arch i386" = "$rvm_archflags" ]] ; then + elif [[ "-arch i386" = "${rvm_archflags:-""}" ]] ; then rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=i386-apple-darwin$(uname -r) --host=i386-apple-darwin$(uname -r)" else rvm_archflags="-arch x86_64" rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=x86_64-apple-darwin$(uname -r) --host=x86_64-apple-darwin$(uname -r)" fi fi - if [[ -n "$rvm_archflags" ]] ; then + if [[ -n "${rvm_archflags:-""}" ]] ; then ARCHFLAGS="$rvm_archflags" ; export ARCHFLAGS # Use the latest sdk available. - if [[ -z "$rvm_sdk" ]] ; then rvm_sdk="$(/usr/bin/basename -a /Developer/SDKs/* | awk '/^M/' | sort | tail -n 1)" ; fi + if [[ -z "${rvm_sdk:-""}" ]] ; then + rvm_sdk="$(/usr/bin/basename -a /Developer/SDKs/* | awk '/^M/' | sort | tail -n 1)" + fi CFLAGS="${CFLAGS:-"-isysroot /Developer/SDKs/$rvm_sdk $rvm_archflags"}" ; export CFLAGS LDFLAGS="${LDFLAGS:-"-Wl,-syslibroot /Developer/SDKs/$rvm_sdk $rvm_archflags"}" ; export LDFLAGS # CXXFLAGS="-mmacosx-version-min="$(sw_vers -productVersion | awk -F'.' '{print $1"."$2}')" -isysroot /Developer/SDKs/$rvm_sdk " ; export CXXFLAGS fi fi @@ -706,23 +690,22 @@ return 0 } __rvm_ensure_has_environment_files() { local environment_identifier="$(__rvm_environment_identifier)" - local 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}:-""}" - eval "value=\$${variable}" - if [[ -n "$value" ]] ; then printf "${variable}='$value'\nexport ${variable}\n" >> "$file_name" else printf "unset ${variable}\n" >> "$file_name" fi @@ -939,40 +922,41 @@ } # Checks the rvmrc for the given directory. Note that if # argument is passed, it will be used instead of pwd. __rvm_project_rvmrc() { - declare -i rvm_project_rvmrc_default=${rvm_project_rvmrc_default:-0} - declare rvm_rvmrc_cwd="${rvm_rvmrc_cwd:-""}" - declare rvm_previous_environment="${rvm_previous_environment:-""}" - local cwd # Get the first argument or the pwd. cwd="${1:-"$PWD"}" + while : ; do if [[ -z "$cwd" || "$HOME" = "$cwd" || "/" = "$cwd" ]] ; then - if [[ -n "$rvm_rvmrc_cwd" ]] ; then - if [[ $rvm_project_rvmrc_default -eq 1 ]]; then + if [[ -n "${rvm_rvmrc_cwd:-""}" ]] ; then + if [[ ${rvm_project_rvmrc_default:-0} -eq 1 ]]; then __rvm_load_env_file "default" - elif [[ -n "$rvm_previous_environment" ]] ; then + elif [[ -n "${rvm_previous_environment:-""}" ]] ; then __rvm_load_env_file "$rvm_previous_environment" fi - rvm_rvmrc_cwd="" - rvm_previous_environment="" + unset rvm_rvmrc_cwd rvm_previous_environment fi break else if [[ -f "$cwd/.rvmrc" ]] ; then - if [[ "$rvm_rvmrc_cwd" != "$cwd" ]] ; then + + if [[ "${rvm_rvmrc_cwd:-""}" != "$cwd" ]] ; then + __rvm_check_rvmrc_trustworthiness "$cwd/.rvmrc" + local rvm_trustworthiness_result="$?" + if [[ "$rvm_trustworthiness_result" = 0 ]]; then rvm_previous_environment="$(__rvm_environment_identifier)" rvm_rvmrc_cwd="$cwd" source "$cwd/.rvmrc" return 0 + else return "$rvm_trustworthiness_result" fi fi break @@ -1021,33 +1005,41 @@ } __rvm_environment_identifier() { local path local string - path="$(command -v ruby)" - string="${path//*rubies\//}" + path="${GEM_HOME:-""}" + string="${path//*gems\//}" string="${string//\/*/}" echo "${string:-system}" return $? } __rvm_expand_ruby_string() { local string="$1" + if [[ -z "$string" || "$string" = "all" ]]; then "$rvm_scripts_path/list" strings | tr ' ' "\n" | __rvm_strip + elif [[ "$string" = "all-gemsets" ]]; then "$rvm_scripts_path/list" gemsets strings | __rvm_strip + elif [[ "$string" = "default-with-rvmrc" || "$string" = "rvmrc" ]]; then "$rvm_scripts_path/tools" path-identifier "$PWD" + elif [[ "$string" == "all-rubies" || "$string" = "rubies" ]]; then "$rvm_scripts_path/list" rubies strings | __rvm_strip + elif [[ "$string" == "current-ruby" || "$string" = "gemsets" ]]; then local current_ruby="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $string}')" rvm_silence_logging=1 "$rvm_scripts_path/gemsets" list | sed "s/^/$current_ruby$rvm_gemset_separator/" | __rvm_strip + elif [[ "$string" = "current" ]]; then __rvm_environment_identifier + elif [[ "$string" = "aliases" ]]; then awk -F= '{print $string}' < "$rvm_config_path/alias" | __rvm_strip + else echo "$string" | tr "," "\n" | __rvm_strip fi return $? }