scripts/gemsets in rvm-1.0.1 vs scripts/gemsets in rvm-1.0.2

- old
+ new

@@ -13,17 +13,17 @@ exit 1 } gemset_update() { if [[ -z "$rvm_ruby_strings" ]]; then - $rvm_scripts_path/log "info" "Running gem update for all rubies and gemsets." + "$rvm_scripts_path/log" "info" "Running gem update for all rubies and gemsets." rvm_ruby_strings="$(\ls "$rvm_gems_path" | \grep -v '^\(doc\|cache\|@\|system\)' | \tr '\n' ',')" else - $rvm_scripts_path/log "info" "Running gem update for the specified rubies." + "$rvm_scripts_path/log" "info" "Running gem update for the specified rubies." fi export rvm_ruby_strings - $rvm_scripts_path/set "gem" "update" + "$rvm_scripts_path/set" "gem" "update" return $? } gemset_globalcache() { if [[ "$1" == "enabled" ]]; then @@ -33,36 +33,36 @@ if [[ "$globalcache_enabled" == "0" ]]; then gc_status="Enabled" else gc_status="Disabled" fi - $rvm_scripts_path/log "info" "Gemset global cache is currently: $gc_status" + "$rvm_scripts_path/log" "info" "Gemset global cache is currently: $gc_status" return "$globalcache_enabled" elif [[ "$1" == "disable" ]]; then - $rvm_scripts_path/log "info" "Removing the global cache (note: this will empty the caches)" + "$rvm_scripts_path/log" "info" "Removing the global cache (note: this will empty the caches)" for directory_name in $(\ls "$rvm_gems_path"); do current_cache_path="$rvm_gems_path/$directory_name/cache" if [[ -L "$current_cache_path" && "$(readlink "$current_cache_path")" == "$rvm_gems_cache_path" ]]; then - $rvm_scripts_path/log "info" "Reverting the gem cache for $directory_name to an empty directory." + "$rvm_scripts_path/log" "info" "Reverting the gem cache for $directory_name to an empty directory." \rm -f "$current_cache_path" 2>/dev/null \mkdir -p "$current_cache_path" 2>/dev/null fi done; unset full_directory_path directory_name - $rvm_scripts_path/db "$rvm_config_path/user" "use_gemset_globalcache" "delete" + "$rvm_scripts_path/db" "$rvm_config_path/user" "use_gemset_globalcache" "delete" elif [[ "$1" == "enable" ]]; then - $rvm_scripts_path/log "info" "Enabling global cache for gems." + "$rvm_scripts_path/log" "info" "Enabling global cache for gems." \mkdir -p "$rvm_gems_cache_path" for directory_name in $(\ls "$rvm_gems_path"); do current_cache_path="$rvm_gems_path/$directory_name/cache" if [[ -d "$current_cache_path" && ! -L "$current_cache_path" ]]; then - $rvm_scripts_path/log "info" "Moving the gem cache for $directory_name to the global cache." + "$rvm_scripts_path/log" "info" "Moving the gem cache for $directory_name to the global cache." mv "$current_cache_path/"*.gem "$rvm_gems_cache_path/" 2>/dev/null \rm -rf "$current_cache_path" ln -nfs "$rvm_gems_cache_path" "$current_cache_path" fi done; unset full_directory_path directory_name - $rvm_scripts_path/db "$rvm_config_path/user" "use_gemset_globalcache" "true" + "$rvm_scripts_path/db" "$rvm_config_path/user" "use_gemset_globalcache" "true" else printf "Usage: 'rvm gemset globalcache {enable,disable}\n" printf " Enable / Disable the use of a global gem cachedir.\n" return 1 fi @@ -78,11 +78,11 @@ gemset_create() { rvm_ruby_gem_prefix=$(echo $rvm_ruby_gem_home | sed 's/'${rvm_gemset_separator}'.*$//') for gemset in $(echo $gems_args) ; do if [[ "$gemset" == *"${rvm_gemset_separator}"* ]]; then - $rvm_scripts_path/log "error" "Can't do that, it contains a \"${rvm_gemset_separator}\"." + "$rvm_scripts_path/log" "error" "Can't do that, it contains a \"${rvm_gemset_separator}\"." continue fi gem_home="${rvm_ruby_gem_prefix}${rvm_gemset_separator}${gemset}" \mkdir -p "$gem_home" # When the globalcache is enabled, we need to ensure we setup the cache directory correctly. @@ -91,107 +91,107 @@ mv "$gem_home/cache"/*.gem "$rvm_gems_cache_path/" 2>/dev/null \rm -rf "$gem_home/cache" fi ln -nfs "$rvm_gems_cache_path" "$gem_home/cache" fi - $rvm_scripts_path/log "info" "Gemset '$gemset' created." + "$rvm_scripts_path/log" "info" "Gemset '$gemset' created." done ; unset gem_home } gemset_list() { if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi - $rvm_scripts_path/log "info" "gemsets : for $rvm_ruby_string (found in $rvm_gems_path/)" + "$rvm_scripts_path/log" "info" "gemsets : for $rvm_ruby_string (found in $rvm_gems_path/)" if [[ ! -z "$rvm_gems_path" ]] ; then - if [[ ! -z $rvm_ruby_string ]] ; then - \ls ${rvm_gems_path}/ | awk -F"${rvm_gemset_separator}" "/${rvm_ruby_string}${rvm_gemset_separator}/{print \$2}" 2>/dev/null + if [[ ! -z "$rvm_ruby_string" ]] ; then + \ls "${rvm_gems_path}/" | awk -F"${rvm_gemset_separator}" "/${rvm_ruby_string}${rvm_gemset_separator}/{print \$2}" 2>/dev/null else - $rvm_scripts_path/log "error" "\$rvm_ruby_string is not set!" + "$rvm_scripts_path/log" "error" "\$rvm_ruby_string is not set!" fi else - $rvm_scripts_path/log "error" "\$rvm_gems_path is not set!" + "$rvm_scripts_path/log" "error" "\$rvm_gems_path is not set!" fi } gemset_delete() { if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi if [[ ! -z "$rvm_gemset_name" ]] ; then gemdir="$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator}$rvm_gemset_name" if [[ -d "$gemdir" ]] && [[ "$gemdir" != '/' ]] && [[ ! -z "$rvm_force_flag" ]] ; then \rm -rf "$gemdir" elif [[ -d "$gemdir" ]] ; then - $rvm_scripts_path/log "warn" "Are you SURE you wish to remove the entire gemset directory '$rvm_gemset_name' ($gemdir)?" + "$rvm_scripts_path/log" "warn" "Are you SURE you wish to remove the entire gemset directory '$rvm_gemset_name' ($gemdir)?" echo -n "(anything other than 'yes' will cancel) > " read response if [[ "yes" = "$response" ]] ; then \rm -f $gemdir/cache 2>/dev/null \rm -rf $gemdir else - $rvm_scripts_path/log "info" "Not doing anything, phew... close call that one eh?" + "$rvm_scripts_path/log" "info" "Not doing anything, phew... close call that one eh?" fi else - $rvm_scripts_path/log "info" "$gemdir already does not exist." + "$rvm_scripts_path/log" "info" "$gemdir already does not exist." fi ; unset gemdir else - $rvm_scripts_path/log "error" "A gemset name must be specified in order to delete a gems." + "$rvm_scripts_path/log" "error" "A gemset name must be specified in order to delete a gems." fi } gemset_empty() { if [[ -z "$rvm_ruby_gem_home" ]] ; then __rvm_select ; fi gemdir="$rvm_ruby_gem_home" if [[ -d "$gemdir" ]] && [[ "$gemdir" != '/' ]] && [[ ! -z "$rvm_force_flag" ]] ; then - builtin cd $gemdir && \rm -rf ./bin/* ./doc/* ./gems/* ./specifications/* + builtin cd "$gemdir" && \rm -rf ./bin/* ./doc/* ./gems/* ./specifications/* elif [[ -d "$gemdir" ]] ; then - $rvm_scripts_path/log "warn" "Are you SURE you wish to remove the installed gemset for gemset '$(basename $gemdir)' ($gemdir)?" + "$rvm_scripts_path/log" "warn" "Are you SURE you wish to remove the installed gemset for gemset '$(basename "$gemdir")' ($gemdir)?" echo -n "(anything other than 'yes' will cancel) > " read response if [[ "yes" = "$response" ]] ; then - builtin cd $gemdir && \rm -rf ./bin/* ./doc/* ./gems/* ./specifications/* + builtin cd "$gemdir" && \rm -rf ./bin/* ./doc/* ./gems/* ./specifications/* else - $rvm_scripts_path/log "info" "Not doing anything, phew... close call that one eh?" + "$rvm_scripts_path/log" "info" "Not doing anything, phew... close call that one eh?" fi else - $rvm_scripts_path/log "info" "$gemdir already does not exist." + "$rvm_scripts_path/log" "info" "$gemdir already does not exist." fi ; unset gemdir } # Migrate gemsets from ruby X to ruby Y gemset_copy() { - local source_ruby="$(echo "$gems_args" | awk '{print $1}')" - local destination_ruby="$(echo "$gems_args" | awk '{print $2}')" + local source_ruby="${gems_args/ */}" + local destination_ruby="${gems_args/* /}" if [[ -z "$destination_ruby" || -z "$source_ruby" ]] ; then - $rvm_scripts_path/log "error" "Source and destination must be specified: 'rvm gemset copy X Y'" + "$rvm_scripts_path/log" "error" "Source and destination must be specified: 'rvm gemset copy X Y'" return 1 fi local source_path="$(rvm_silence_logging=1 rvm "$source_ruby" gem env gemdir)" local destination_path="$(rvm_silence_logging=1 rvm "$destination_ruby" gem env gemdir)" if [[ -z "$source_path" ]]; then - $rvm_scripts_path/log "error" "Unable to expand ruby '$source_ruby'" + "$rvm_scripts_path/log" "error" "Unable to expand ruby '$source_ruby'" return 1 fi if [[ -z "$destination_path" ]]; then - $rvm_scripts_path/log "error" "Unable to expand ruby '$destination_ruby'" + "$rvm_scripts_path/log" "error" "Unable to expand ruby '$destination_ruby'" return 1 fi if [[ -d "$source_path" ]] ; then [[ ! -d "$destination_path" ]] && \mkdir -p "$destination_path" - $rvm_scripts_path/log "info" "Copying gemset from $source_ruby to $destination_ruby" + "$rvm_scripts_path/log" "info" "Copying gemset from $source_ruby to $destination_ruby" for dir in bin doc gems specifications cache ; do \mkdir -p "$destination_path/$dir" \cp -Rf "$source_path/$dir" "$destination_path/" done - $rvm_scripts_path/log "info" "Making gemset for $destination_ruby pristine." + "$rvm_scripts_path/log" "info" "Making gemset for $destination_ruby pristine." __rvm_run_with_env "gemset.pristine" "$destination_ruby" "rvm gemset pristine" else - $rvm_scripts_path/log "error" "Gems directory does not exist for $source_path ($source_path)" + "$rvm_scripts_path/log" "error" "Gems directory does not exist for $source_path ($source_path)" return 1 fi } gemset_export() { @@ -209,18 +209,18 @@ else rvm_file_name="default.gems" fi fi - $rvm_scripts_path/log "info" "Exporting current environments gemset to $rvm_file_name" + "$rvm_scripts_path/log" "info" "Exporting current environments gemset to $rvm_file_name" - \touch $rvm_file_name - echo "# $rvm_file_name generated gem export file. Note that any env variable settings will be missing. Append these after using a ';' field separator" > $rvm_file_name + \touch "$rvm_file_name" + echo "# $rvm_file_name generated gem export file. Note that any env variable settings will be missing. Append these after using a ';' field separator" > "$rvm_file_name" for gem in $(gem list | sed 's#[\(|\)]##g' | sed 's#, #,#g' | \tr ' ' ';') ; do - name="$(echo $gem | awk -F';' '{print $1}')" + name="${gem/;*/}" if [[ -z "$rvm_latest_flag" ]] ; then - versions="$(echo $gem | awk -F';' '{print $2}' | sed 's#,# #g')" + versions="${gem/*;/}" ; versions="${versions//,/ }" for version in $versions ; do echo "$name -v$version" >> $rvm_file_name done ; unset version versions else echo "$name" >> $rvm_file_name @@ -234,69 +234,66 @@ export GEM_HOME="$rvm_ruby_gem_home" export GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator}global/bin" export BUNDLE_PATH="$rvm_ruby_gem_home" fi - if [[ ! -z "$(echo "$gems_args" | awk '/\.gem.*$/')" ]] ; then - rvm_gemset_name="$(echo "$gems_args" | sed 's#\.gem.*##g' | sed 's# ##g')" - else - rvm_gemset_name="$(echo "$gems_args" | sed 's# ##g')" - fi + rvm_gemset_name="${gems_args//.gem*/}" + rvm_gemset_name="${gems_args// /}" if [[ -s "$rvm_gemset_name.gems" ]] ; then rvm_file_name="$rvm_gemset_name.gems" elif [[ -s "default.gems" ]] ; then rvm_file_name="default.gems" elif [[ -s "system.gems" ]] ; then rvm_file_name="system.gems" elif [[ -s ".gems" ]] ; then rvm_file_name=".gems" else - $rvm_scripts_path/log "error" "No *.gems file found." + "$rvm_scripts_path/log" "error" "No *.gems file found." return 1 fi \mkdir -p "$rvm_gems_cache_path" # Ensure the base cache dir is initialized. if [[ -s "$rvm_file_name" ]] ; then echo "Importing $rvm_file_name file..." - rvm_ruby_gem_list=$(\ls $rvm_ruby_gem_home/specifications/ 2> /dev/null | sed 's#.gems.*$##' 2> /dev/null) + rvm_ruby_gem_list=$(\ls "$rvm_ruby_gem_home/specifications/" 2> /dev/null | sed 's#.gems.*$##' 2> /dev/null) while read -r line do # Keep this on 2nd line :( - if [[ ! -z "$(echo $line | sed 's/\s//g')" ]] ; then + if [[ -n "${line// /}" ]] ; then gems_args="$line" ; gem_install fi done < <(awk '/^[^#]+/{print}' "${rvm_file_name}") else - $rvm_scripts_path/log "error" "${rvm_file_name} does not exist to import from." + "$rvm_scripts_path/log" "error" "${rvm_file_name} does not exist to import from." fi } __rvm_parse_gems_args() { - gem="$(echo $gems_args | awk -F';' '{print $1}')" - gem_prefix="$(echo $gems_args | awk -F';' '{print $2}')" - if $rvm_scripts_path/match "$gem" "\.gem$" ; then - gem_name="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{$NF=NULL;print}')" - gem_version="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{print $NF}' )" - gem_postfix="$(basename $gem | sed "s#.*\.gem##")" + gem="${gems_args/;*}" + gem_prefix="${gems_args/*;}" + if "$rvm_scripts_path/match" "$gem" ".gem$" ; then + gem_name="$(basename "${gem/.gem/}" | awk -F'-' '{$NF=NULL;print}')" + gem_version="$(basename "${gem/.gem/}" | awk -F'-' '{print $NF}' )" + gem_postfix="$(basename "${gem/*.gem/}")" else - gem_name="$(echo $gem | awk '{print $1}')" - if $rvm_scripts_path/match "$gem" "--version" ; then - gem_version="$(echo $gem | sed 's#.*--version[=]*[ ]*##' | awk '{print $1}')" - gem_postfix="$(echo $gem | sed "s#${gem_name/ /}##" | sed "s#--version[=]*[ ]*${gem_version/ /}##")" - elif $rvm_scripts_path/match "$gem" "-v" ; then - gem_version="$(echo $gem | sed 's#.*-v[=]*[ ]*##' | awk '{print $1}')" - gem_postfix="$(echo $gem | sed "s#${gem_name/ /}##" | sed "s#-v[=]*[ ]*${gem_version/ /}##")" + gem_name="${gem/ */}" + if "$rvm_scripts_path/match" "$gem" "--version" ; then + gem_version="$(echo "$gem" | sed -e 's#.*--version[=]*[ ]*##' | awk '{print $1}')" + gem_postfix="$(echo "$gem" | sed -e "s#${gem_name/ /}##" -e "s#--version[=]*[ ]*${gem_version/ /}##")" + elif "$rvm_scripts_path/match" "$gem" "-v" ; then + gem_version="$(echo "$gem" | sed -e 's#.*-v[=]*[ ]*##' | awk '{print $1}')" + gem_postfix="$(echo "$gem" | sed -e "s#${gem_name/ /}##" -e "s#-v[=]*[ ]*${gem_version/ /}##")" else unset gem_version # no version fi fi if [[ -s "$gem" ]] ; then gem_file_name="$gem" - elif $rvm_scripts_path/match "$gem" ".gem$" ; then + elif "$rvm_scripts_path/match" "$gem" ".gem$" ; then gem_file_name="$gem" elif [[ -z "${gem_version/ /}" ]] ; then gem_file_name="${gem_name/ /}*.gem" else # version gem_file_name="${gem_name/ /}-${gem_version/ /}.gem" @@ -308,13 +305,13 @@ # First we parse the gem args to pick apart the pieces. __rvm_parse_gems_args # Now we determine if a .gem cache file is already installed - if [[ -z "$rvm_force_flag" ]] && [[ -f "${rvm_ruby_gem_home}/specifications/$(basename $gem_file_name)spec" ]] ; then + if [[ -z "$rvm_force_flag" ]] && [[ -f "${rvm_ruby_gem_home}/specifications/$(basename "$gem_file_name")spec" ]] ; then unset gem - $rvm_scripts_path/log "info" "$gem_name $gem_version exists, skipping (--force to re-install)" + "$rvm_scripts_path/log" "info" "$gem_name $gem_version exists, skipping (--force to re-install)" else if [[ -s "$gem" ]] ; then cache_file="$gem" elif [[ -s "$(__rvm_current_gemcache_dir)/${gem_file_name}" ]] ; then cache_file="$(__rvm_current_gemcache_dir)/${gem_file_name}" @@ -334,11 +331,11 @@ gem_file_name="$(basename "$cache_file")" gem_string="$(echo "$gem_file_name" | sed 's#\.gem$##')" if [[ -z "$rvm_force_flag" ]] && [[ -s "${rvm_ruby_gem_home}/specifications/$(basename $gem_file_name)spec" ]] ; then unset gem # already installed, not forcing reinstall. - $rvm_scripts_path/log "info" "$gem_name $gem_version exists, skipping (--force to re-install)" + "$rvm_scripts_path/log" "info" "$gem_name $gem_version exists, skipping (--force to re-install)" else if [[ -s "$(__rvm_current_gemcache_dir)/$(basename $gem_file_name)" ]] ; then \mkdir -p "$rvm_tmp_path/$$/" mv "$(__rvm_current_gemcache_dir)/$gem_file_name" "$rvm_tmp_path/$$/$gem_file_name" gem="$rvm_tmp_path/$$/$gem_file_name -f -l" @@ -361,13 +358,13 @@ command="$gem_prefix gem install --ignore-dependencies $gems_args $rvm_gem_options -q $gem $gem_postfix $vars" fi __rvm_run "gem.install" "$command" "installing ${gem_name} ${gem_version}..." result=$? if [[ $result -eq 0 ]] ; then - $rvm_scripts_path/log "info" "$gem_name $gem_version installed, output logged to:\n$rvm_path/log/$rvm_ruby_string/gem.install.log" + "$rvm_scripts_path/log" "info" "$gem_name $gem_version installed, output logged to:\n$rvm_path/log/$rvm_ruby_string/gem.install.log" else - $rvm_scripts_path/log "error" "$gem_name $gem_version failed to install, output logged to:\n$rvm_path/log/$rvm_ruby_string/gem.install.error.log" + "$rvm_scripts_path/log" "error" "$gem_name $gem_version failed to install, output logged to:\n$rvm_path/log/$rvm_ruby_string/gem.install.error.log" fi fi ; unset gem gem_prefix gem_name gem_version gem_file_name gem_postfix cache_file gem_file_name gem_string gem_action return $result } @@ -389,23 +386,23 @@ gemset_prune() { temporary_cache_path="$GEM_HOME/temporary-cache" live_cache_path="$GEM_HOME/cache" \mkdir -p "$temporary_cache_path" - $rvm_scripts_path/log "info" "Moving active gems into temporary cache..." + "$rvm_scripts_path/log" "info" "Moving active gems into temporary cache..." while read -r used_gem; do gem_name="$(echo "$used_gem" | sed -e 's/ .*//')" - versions="$(echo "$used_gem" | sed -e 's/.* (//' -e 's/)//' | \tr ', ' ' ')" + versions="$(echo "${used_gem//, / }" | sed -e 's/.* (//' -e 's/)//')" for version in $versions; do cached_gem_name="${gem_name}-${version}.gem" cached_file_path="${live_cache_path}/${cached_gem_name}" if [[ -f "$cached_file_path" ]]; then mv "$cached_file_path" "${temporary_cache_path}/${cached_gem_name}" fi done done < <(gem list --versions) - $rvm_scripts_path/log "info" "Removing live cache and restoring temporary cache..." + "$rvm_scripts_path/log" "info" "Removing live cache and restoring temporary cache..." # Switch the cache back. \rm -rf "$live_cache_path" mv "$temporary_cache_path" "$live_cache_path" } @@ -413,11 +410,11 @@ gem pristine --all } # Loads the default gemsets for the current interpreter and gemset. gemset_initial() { - $rvm_scripts_path/log "info" "Importing initial gemsets for $(__rvm_environment_identifier)." + "$rvm_scripts_path/log" "info" "Importing initial gemsets for $(__rvm_environment_identifier)." \mkdir -p "$rvm_gemsets_path/$(echo "$rvm_ruby_string" | \tr '-' '/')" 2>/dev/null for gemsets_path in $(__rvm_ruby_string_paths_under "$rvm_gemsets_path") ; do if [[ -n "$rvm_gemset_name" ]] ; then if [[ -s "${gemsets_path}/${rvm_gemset_name}.gems" ]] ; then (source "$rvm_scripts_path/rvm"; rvm gemset import "${gemsets_path}/${rvm_gemset_name}.gems") > /dev/null @@ -429,21 +426,21 @@ if [[ -d "$gemsets_path" ]] && [[ -s "${gemsets_path}/global.gems" ]] ; then (source "$rvm_scripts_path/rvm"; rvm use "$rvm_ruby_string@global" --create ; rvm gemset import "${gemsets_path}/global.gems") > /dev/null fi fi done - $rvm_scripts_path/log "info" "Installation of gems for $(__rvm_environment_identifier) is complete." + "$rvm_scripts_path/log" "info" "Installation of gems for $(__rvm_environment_identifier) is complete." } unset GEM_PATH if ! command -v gem > /dev/null ; then - $rvm_scripts_path/log "error" "'gem' was not found, cannot perform gem actions (Do you have an RVM ruby selected?)" + "$rvm_scripts_path/log" "error" "'gem' was not found, cannot perform gem actions (Do you have an RVM ruby selected?)" exit 1 fi -action="$(echo $* | awk '{print $1}')" +action="$(echo "$*" | awk '{print $1}')" gems_args="$(echo "$*" | awk '{$1="" ; print}' | __rvm_strip)" export rvm_gemset_name if [[ "import" = "$action" ]] || [[ "load" = "$action" ]] ; then if [[ -z "$rvm_ruby_strings" ]]; then @@ -486,10 +483,10 @@ elif [[ "update" = "$action" ]]; then gemset_update elif [[ "globalcache" = "$action" ]]; then gemset_globalcache "$2" elif [[ "clear" = "$action" ]] ; then - $rvm_scripts_path/log "info" "gemset cleared." + "$rvm_scripts_path/log" "info" "gemset cleared." exit 0 else usage fi