scripts/utility in rvm-1.0.0 vs scripts/utility in rvm-1.0.1

- old
+ new

@@ -154,16 +154,18 @@ # 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#:$##') export PATH + builtin hash -r } # Clean all rvm items out of the current working path. __rvm_remove_rvm_from_path() { - PATH=$(echo $PATH | \tr -s ':' '\n' | \grep -v "\.rvm" | \tr -s '\n' ':' | sed 's#:$##') + PATH=$(echo $PATH | \tr -s ':' '\n' | \grep -v "rvm" | \tr -s '\n' ':' | sed 's#:$##') export PATH + builtin hash -r } # Run a specified command and log it. __rvm_run() { log_file_name="$1" ; command="$2" ; message="$3" @@ -281,20 +283,20 @@ __rvm_cleanup_temp_on_exit() { trap "__rvm_cleanup_temp_for '$$'" 0 1 2 3 15 } __rvm_set_rvmrc() { - if [[ "$HOME" != "$(pwd)" ]] ; then + if [[ "$HOME" != "$PWD" ]] ; then if [[ "$rvm_verbose_flag" -eq 1 ]] ; 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 local identifier=$(__rvm_environment_identifier) - printf "if [[ -n \"\$rvm_environments_path\" && -s \"\$rvm_environments_path/$identifier\" ]] ; then\n . \"\$rvm_environments_path/$identifier\"" > .rvmrc + printf "if [[ -n \"\$rvm_environments_path\" && -s \"\$rvm_environments_path/$identifier\" ]] ; then\n \\. \"\$rvm_environments_path/$identifier\"" > .rvmrc printf "\nelse\n rvm --create $flags \"$identifier\"\nfi" >> .rvmrc unset flags else $rvm_scripts_path/log "error" ".rvmrc cannot be set in your home directory. \n The home .rvmrc is for global rvm settings only." @@ -352,15 +354,25 @@ # TODO: Adjust binscript to be able to handle all rubies not just the standard interpreteres. __rvm_bin_script() { $rvm_scripts_path/wrapper "$rvm_ruby_string" } +# Add bin path if not present +__rvm_conditionally_add_bin_path() { + if echo "$PATH" | \tr ':' ' ' | \grep -vqF "$rvm_bin_path " ; then + PATH="$rvm_bin_path:$PATH" + builtin hash -r + 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 + __rvm_remove_rvm_from_path + __rvm_conditionally_add_bin_path + export PATH + builtin hash -r for flag in default passenger editor ; do \rm -f "$rvm_bin_path"/${flag}_* ; done unset flag for file in system default ; do @@ -420,14 +432,12 @@ rvm_ruby_load_path="." rvm_ruby_require="" __rvm_clean_path - if echo "$PATH" | \grep -q 'rvm\/bin:' ; then - PATH="${rvm_bin_path}:$PATH" - export PATH - fi + __rvm_conditionally_add_bin_path + export PATH \mkdir -p "$rvm_src_path" "$rvm_bin_path" "$rvm_archives_path" "$rvm_gems_path" "$rvm_tmp_path" "$rvm_repo_path" } # Update rubygems or binscripts based on CLI selection. @@ -460,11 +470,11 @@ else 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 "extract" "cat $rvm_archives_path/rvm-${stable_version}.tar.gz | gunzip | 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_pushpop @@ -529,16 +539,16 @@ # Output an inspection of selected 'binary' scripts, based on CLI selection. __rvm_inspect() { for binary in $rvm_ruby_args ; do actual_file="$(command -v $binary)" $rvm_scripts_path/log "info" "$actual_file:" - if [[ -n "$rvm_shebang_flag" ]] ; then cat $actual_file | head -n 1 ; fi - if [[ -n "$rvm_env_flag" ]] ; then cat $actual_file | awk '/ENV/' ; fi - if [[ -n "$rvm_path_flag" ]] ; then cat $actual_file | awk '/PATH/' ; fi - if [[ -n "$rvm_head_flag" ]] ; then cat $actual_file | head -n 5 ; fi - if [[ -n "$rvm_tail_flag" ]] ; then cat $actual_file | tail -n 5 ; fi - if [[ -n "$rvm_all_flag" ]] ; then cat $actual_file ; fi + if [[ -n "$rvm_shebang_flag" ]] ; then head -n 1 < "$actual_file" ; fi + if [[ -n "$rvm_env_flag" ]] ; then awk '/ENV/' < "$actual_file" ; fi + if [[ -n "$rvm_path_flag" ]] ; then awk '/PATH/' < "$actual_file" ; fi + if [[ -n "$rvm_head_flag" ]] ; then head -n 5 < "$actual_file" ; fi + if [[ -n "$rvm_tail_flag" ]] ; then tail -n 5 < "$actual_file" ; fi + if [[ -n "$rvm_all_flag" ]] ; then cat $actual_file ; fi done } # Attempt to override the Darwin build settings for rubies # This should only be used in extreme edge cases that will not work via the default way. @@ -578,10 +588,11 @@ export C_INCLUDE_PATH="$rvm_usr_path/include:$C_INCLUDE_PATH" export ACLOCAL_PATH="$rvm_usr_path/share/aclocal" export ACLOCAL_FLAGS="-I $ACLOCAL_PATH" export PKG_CONFIG_PATH="$rvm_usr_path/lib/pkgconfig:$PKG_CONFIG_PATH" PATH="$rvm_usr_path/bin:$PATH" + builtin hash -r } __rvm_become() { [[ -n "$1" ]] && rvm_ruby_string="$1" { __rvm_ruby_string && __rvm_select && __rvm_use; } > /dev/null 2>&1 @@ -636,11 +647,11 @@ echo "${rvm_ruby_gem_home:-"$GEM_HOME"}/cache" 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 + for index in {1..750} ; do sleep 0.25 ; echo -n '.' ; done ; printf "%d" 0x2A ; echo } __rvm_ultimate_question() { printf "\nI do not know the Ultimate Question, " printf "\nhowever I can help you build a more " @@ -649,12 +660,13 @@ } __rvm_load_env_file() { if [[ -f "$rvm_environments_path/$1" ]]; then # Restore the path to it's state minus rvm - PATH="$(echo $PATH | \tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)" - . "$rvm_environments_path/$1" + __rvm_remove_rvm_from_path + \. "$rvm_environments_path/$1" + builtin hash -r else rvm use "$1" >/dev/null 2>&1 fi } @@ -718,31 +730,32 @@ else echo "The trustiworthiness of '$rvmrc_path' is currently unknown." fi ;; load) - rvm_trust_rvmrcs=1 __rvm_project_rvmrc "$(dirname "$rvmrc_path")" + rvm_rvmrc_cwd="" rvm_trust_rvmrcs=1 __rvm_project_rvmrc "$(dirname "$rvmrc_path")" ;; *) echo "Usage: rvm rvmrc {trust,untrust,trusted,load,reset}" return 1 ;; esac } __rvm_check_rvmrc_trustworthiness() { # Trust when they have the flag... of doom! - [[ -z "$1" || "$rvm_trust_rvmrcs" = "1" ]] && return + [[ -z "$1" || "$rvm_trust_rvmrcs" = "1" ]] && return 0 value="$(__rvm_rvmrc_stored_trust "$1")" if [[ -z "$value" ]] ; then __rvm_ask_to_trust "$1" else [[ "$value" = "1" ]] fi } __rvm_ask_to_trust() { + [[ -n "$rvm_promptless" ]] && return 2 echo "Changing into a directory with an untrusted .rvmrc" echo "Do you wish to trust the rvmrc in this directory? It contains:" echo "---" echo "" cat "$1" @@ -773,11 +786,11 @@ # Checks the rvmrc for the given directory. Note that if # argument is passed, it will be used instead of pwd. __rvm_project_rvmrc() { local cwd # Get the first argument or the pwd. - cwd="${1:-"$(pwd)"}" + cwd="${1:-"$PWD"}" while : ; do if [[ -z "$cwd" || "$HOME" = "$cwd" || "/" = "$cwd" ]] ; then if [[ -n "$rvm_rvmrc_cwd" ]] ; then if [[ "$rvm_project_rvmrc_default" = "1" ]]; then __rvm_load_env_file "default" @@ -787,14 +800,19 @@ fi break else if [[ -f "$cwd/.rvmrc" ]] ; then if [[ "$rvm_rvmrc_cwd" != "$cwd" ]] ; then - if __rvm_check_rvmrc_trustworthiness "$cwd/.rvmrc" ; 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 else cwd="$(dirname "$cwd")" @@ -808,32 +826,32 @@ local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1")" local rvm_install_record_file="$rvm_config_path/installs" local rvm_install_command="$(echo "$recorded_ruby_name $rvm_install_arguments" | __rvm_strip)" \touch "$rvm_install_record_file" \rm -f "$rvm_install_record_file.tmp" - cat "$rvm_install_record_file" | \grep -v "^$recorded_ruby_name " > "$rvm_install_record_file.tmp" + \grep -v "^$recorded_ruby_name " < "$rvm_install_record_file" > "$rvm_install_record_file.tmp" echo "$rvm_install_command" >> "$rvm_install_record_file.tmp" \rm -f "$rvm_install_record_file" mv "$rvm_install_record_file.tmp" "$rvm_install_record_file" } __rvm_remove_install_record() { local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1")" local rvm_install_record_file="$rvm_config_path/installs" if [[ -s "$rvm_install_record_file" ]]; then mv "$rvm_install_record_file" "$rvm_install_record_file.tmp" - cat "$rvm_install_record_file.tmp" | \grep -v "^$recorded_ruby_name " > "$rvm_install_record_file" + \grep -v "^$recorded_ruby_name " < "$rvm_install_record_file.tmp" > "$rvm_install_record_file" \rm -f "$rvm_install_record_file.tmp" fi } __rvm_recorded_install_command() { local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1" | awk -F"$rvm_gemset_separator" '{print $1}')" [[ -z "$recorded_ruby_name" ]] && return 1 local recorded_ruby_match="^$recorded_ruby_name " if [[ -s "$rvm_config_path/installs" ]] && \grep -q "$recorded_ruby_match" "$rvm_config_path/installs" ; then - cat "$rvm_config_path/installs" | \grep "$recorded_ruby_match" | head -n1 + \grep "$recorded_ruby_match" < "$rvm_config_path/installs" | head -n1 else return 1 fi } @@ -851,19 +869,19 @@ if [[ -z "$1" || "$1" = "all" ]]; then $rvm_scripts_path/list strings | tr ' ' "\n" | __rvm_strip elif [[ "$1" = "all-gemsets" ]]; then $rvm_scripts_path/list gemsets strings | __rvm_strip elif [[ "$1" = "default-with-rvmrc" || "$1" = "rvmrc" ]]; then - $rvm_scripts_path/tools path-identifier "$(pwd)" + $rvm_scripts_path/tools path-identifier "$PWD" elif [[ "$1" == "all-rubies" || "$1" = "rubies" ]]; then $rvm_scripts_path/list rubies strings | __rvm_strip elif [[ "$1" == "current-ruby" || "$1" = "gemsets" ]]; then local current_ruby="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $1}')" rvm_silence_logging=1 $rvm_scripts_path/gemsets list | sed "s/^/$current_ruby$rvm_gemset_separator/" | __rvm_strip elif [[ "$1" = "current" ]]; then __rvm_environment_identifier elif [[ "$1" = "aliases" ]]; then - cat "$rvm_config_path/alias" | awk -F= '{print $1}' | __rvm_strip + awk -F= '{print $1}' < "$rvm_config_path/alias" | __rvm_strip else echo "$1" | tr "," "\n" | __rvm_strip fi -} \ No newline at end of file +}