rvm 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/scripts/db CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  usage() {
4
4
  printf "\nUsage:\n" >&2
5
- printf "\n $rvm_scripts_path/db database_file {{key}} {{value}} # set" >&2
6
- printf "\n $rvm_scripts_path/db database_file {{key}} # get" >&2
7
- printf "\n $rvm_scripts_path/db database_file {{key}} unset # unset\n\n" >&2
5
+ printf "\n $rvm_path/scripts/db database_file {{key}} {{value}} # set" >&2
6
+ printf "\n $rvm_path/scripts/db database_file {{key}} # get" >&2
7
+ printf "\n $rvm_path/scripts/db database_file {{key}} unset # unset\n\n" >&2
8
8
  }
9
9
 
10
10
  if [[ -f "$1" ]] ; then
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- source "$rvm_scripts_path/base"
3
+ source "$rvm_path/scripts/base"
4
4
 
5
5
  rvm_ruby_gem_home="${rvm_ruby_gem_home:-$GEM_HOME}"
6
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  #!/usr/bin/env bash
4
4
  rvm_base_except="selector"
5
- source "$rvm_scripts_path/base"
5
+ source "$rvm_path/scripts/base"
6
6
 
7
7
  usage() {
8
8
  printf "Usage: 'rvm disk-usage {all,archives,repos,sources,logs,packages,rubies,gemsets}'\n"
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env bash
2
2
  rvm_base_except="selector"
3
- source "$rvm_scripts_path/base"
3
+ source "$rvm_path/scripts/base"
4
4
 
5
- rvm_docs_ruby_string="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $1}')"
5
+ rvm_docs_ruby_string="$(__rvm_environment_identifier | awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')"
6
6
  if [[ "$rvm_docs_ruby_string" = "system" || -z "$rvm_docs_ruby_string" ]]; then
7
- "$rvm_scripts_path"/log "error" "Currently 'rvm docs ...' does not work with non-rvm rubies."
7
+ "$rvm_path/scripts/log" "error" "Currently 'rvm docs ...' does not work with non-rvm rubies."
8
8
  exit 1
9
9
  fi
10
10
 
@@ -16,8 +16,14 @@ if [[ ! -d "$rvm_docs_path" ]] ; then
16
16
  fi
17
17
 
18
18
  usage() {
19
- printf "Usage: 'rvm docs {open,generate,generate-ri,generate-rdoc}'\n"
20
- exit 1
19
+ printf "
20
+
21
+ Usage:
22
+
23
+ rvm docs {open,generate,generate-ri,generate-rdoc}
24
+
25
+ "
26
+ return 0
21
27
  }
22
28
 
23
29
  open_docs() {
@@ -27,10 +33,10 @@ open_docs() {
27
33
  elif command -v xdg-open >/dev/null ; then
28
34
  xdg-open "$rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type/index.html"
29
35
  else
30
- "$rvm_scripts_path"/log "error" "Neither open nor xdg-open were found, in order to open the docs one of these two are required. \n(OR you can let me know how else to open the html in your browser from comand line on your OS :) )"
36
+ "$rvm_path/scripts"/log "error" "Neither open nor xdg-open were found, in order to open the docs one of these two are required. \n(OR you can let me know how else to open the html in your browser from comand line on your OS :) )"
31
37
  fi
32
38
  else
33
- "$rvm_scripts_path"/log "error" "$rvm_docs_type docs are missing, perhaps run 'rvm docs generate' first?"
39
+ "$rvm_path/scripts"/log "error" "$rvm_docs_type docs are missing, perhaps run 'rvm docs generate' first?"
34
40
  fi
35
41
  }
36
42
 
@@ -38,8 +44,8 @@ generate_ri() {
38
44
  # Generate ri docs
39
45
  (
40
46
  builtin cd "$rvm_src_path/$rvm_docs_ruby_string/"
41
- "$rvm_scripts_path"/log "info" "Generating ri documentation, be aware that this could take a *long* time, and depends heavily on your system resources..."
42
- "$rvm_scripts_path"/log "info" "( Errors will be logged to $rvm_log_path/$rvm_docs_ruby_string/docs.error.log )"
47
+ "$rvm_path/scripts/log" "info" "Generating ri documentation, be aware that this could take a *long* time, and depends heavily on your system resources..."
48
+ "$rvm_path/scripts/log" "info" "( Errors will be logged to $rvm_log_path/$rvm_docs_ruby_string/docs.error.log )"
43
49
  rdoc -a --ri --ri-site > /dev/null 2>> $rvm_log_path/$rvm_docs_ruby_string/docs.error.log
44
50
  )
45
51
  }
@@ -48,8 +54,8 @@ generate_rdoc() {
48
54
  (
49
55
  builtin cd "$rvm_src_path/$rvm_docs_ruby_string/"
50
56
  \rm -rf "$rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type/"
51
- "$rvm_scripts_path"/log "info" "Generating rdoc documentation, be aware that this could take a *long* time, and depends heavily on your system resources..."
52
- "$rvm_scripts_path"/log "info" "( Errors will be logged to $rvm_log_path/$rvm_docs_ruby_string/docs.error.log )"
57
+ "$rvm_path/scripts/log" "info" "Generating rdoc documentation, be aware that this could take a *long* time, and depends heavily on your system resources..."
58
+ "$rvm_path/scripts/log" "info" "( Errors will be logged to $rvm_log_path/$rvm_docs_ruby_string/docs.error.log )"
53
59
  if gem list | \grep -q ^hanna ; then
54
60
  hanna -o "$rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type" --inline-source --line-numbers --fmt=html > /dev/null 2>> "$rvm_log_path/$rvm_docs_ruby_string/docs.error.log"
55
61
  else
@@ -60,14 +66,18 @@ generate_rdoc() {
60
66
 
61
67
  args=($*)
62
68
  action="${args[0]}"
63
- args="$(echo ${args[@]:1}) " # Strip trailing / leading / extra spacing.
69
+ args=($(echo ${args[@]:1})) # Strip trailing / leading / extra spacing.
64
70
 
65
71
  case "$action" in
66
- open) open_docs ;;
67
- generate) generate_ri; generate_rdoc ;;
68
- generate-ri) generate_ri ;;
69
- generate-rdoc) generate_rdoc ;;
70
- *) usage ;;
72
+ generate)
73
+ generate_ri
74
+ generate_rdoc
75
+ ;;
76
+ open) open_docs ;;
77
+ generate-ri) generate_ri ;;
78
+ generate-rdoc) generate_rdoc ;;
79
+ help) usage ;;
80
+ *) usage ; exit 1 ;;
71
81
  esac
72
82
 
73
- exit $result
83
+ exit $?
@@ -2,7 +2,7 @@
2
2
 
3
3
  unset rvm_default_flag # Recursive loops, oh my!
4
4
 
5
- source "$rvm_scripts_path/base"
5
+ source "$rvm_path/scripts/base"
6
6
 
7
7
  usage() {
8
8
  printf "
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- # Usage: $rvm_scripts_path/environment-convertor <shell> <environment>
3
+ # Usage: $rvm_path/scripts/environment-convertor <shell> <environment>
4
4
 
5
5
  unset GREP_COLOR
6
6
  unset GREP_OPTIONS
7
7
 
8
- source "$rvm_scripts_path/base"
8
+ source "$rvm_path/scripts/base"
9
9
 
10
10
  convert_path_to_fish() {
11
11
  local parts path_parts
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  rvm_base_except="selector"
4
- source "$rvm_scripts_path/base"
4
+ source "$rvm_path/scripts/base"
5
5
  result=0
6
6
 
7
7
  # Set it to cleanup the download on interruption.
@@ -17,19 +17,19 @@ record_md5() {
17
17
  else
18
18
  archive_md5="$(md5sum "${archive}" | awk '{print $1}')"
19
19
  fi
20
- "$rvm_scripts_path/db" "$rvm_config_path/md5" "$archive" "$archive_md5"
20
+ "$rvm_path/scripts/db" "$rvm_config_path/md5" "$archive" "$archive_md5"
21
21
  }
22
22
 
23
23
  builtin cd "$rvm_archives_path"
24
24
 
25
25
  # args=($*) # Reserved for future use
26
26
 
27
- if [[ -z "$1" ]] ; then "$rvm_scripts_path/log" "fail" "BUG: $0 called without an argument :/" ; exit 1 ; fi
27
+ if [[ -z "$1" ]] ; then "$rvm_path/scripts/log" "fail" "BUG: $0 called without an argument :/" ; exit 1 ; fi
28
28
 
29
29
  url="$1"; download=1 ; package_name="$2"
30
30
 
31
31
  if ! command -v curl > /dev/null ; then
32
- "$rvm_scripts_path/log" "fail" "rvm requires curl. curl was not found in your active path."
32
+ "$rvm_path/scripts/log" "fail" "rvm requires curl. curl was not found in your active path."
33
33
  exit 1
34
34
  elif [[ ! -z ${rvm_proxy} ]] ; then
35
35
  fetch_command="curl -x${rvm_proxy} -L --create-dirs -C - " # -s for silent
@@ -45,22 +45,22 @@ else
45
45
  archive=$(basename "$url")
46
46
  fi
47
47
 
48
- if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "Fetching $archive" ; fi
48
+ if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_path/scripts/log" "debug" "Fetching $archive" ; fi
49
49
 
50
50
  # Check first if we have the correct archive
51
- archive_md5="$($rvm_scripts_path/db "$rvm_config_path/md5" "$archive" | head -n1)"
51
+ archive_md5="$($rvm_path/scripts/db "$rvm_config_path/md5" "$archive" | head -n1)"
52
52
  if [[ -e "$archive" ]] && [[ ! -z "$archive_md5" ]] ; then
53
- if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "Found archive and its md5, testing correctness" ; fi
54
- if ! "$rvm_scripts_path"/md5 "${rvm_archives_path}/${archive}" "$archive_md5" ; then
55
- if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "Archive is bad, downloading" ; fi
53
+ if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_path/scripts/log" "debug" "Found archive and its md5, testing correctness" ; fi
54
+ if ! "$rvm_path/scripts"/md5 "${rvm_archives_path}/${archive}" "$archive_md5" ; then
55
+ if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_path/scripts/log" "debug" "Archive is bad, downloading" ; fi
56
56
  download=1
57
57
  else
58
- if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "Archive is good, not downloading" ; fi
58
+ if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_path/scripts/log" "debug" "Archive is good, not downloading" ; fi
59
59
  download=0
60
60
  result=0
61
61
  fi ; unset archive_md5
62
62
  else
63
- if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "No archive or no MD5, downloading" ; fi
63
+ if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_path/scripts/log" "debug" "No archive or no MD5, downloading" ; fi
64
64
  download=1
65
65
  fi
66
66
 
@@ -75,18 +75,18 @@ if [[ $download -gt 0 ]] ; then
75
75
  retry=0
76
76
  try_http=0
77
77
  if [[ $result -eq 78 ]] ; then
78
- "$rvm_scripts_path/log" "error" "The requested url does not exist: '$url'"
78
+ "$rvm_path/scripts/log" "error" "The requested url does not exist: '$url'"
79
79
  try_http=1
80
80
  elif [[ $result -eq 18 ]] ; then
81
- "$rvm_scripts_path/log" "error" "Partial file. Only a part of the file was transferred. Removing partial and re-trying."
81
+ "$rvm_path/scripts/log" "error" "Partial file. Only a part of the file was transferred. Removing partial and re-trying."
82
82
  rm -f "$archive"
83
83
  retry=1
84
84
  elif [[ $result -eq 33 ]] ; then
85
- if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "Server does not support 'range' command, removing '$archive'" ; fi
85
+ if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_path/scripts/log" "debug" "Server does not support 'range' command, removing '$archive'" ; fi
86
86
  rm -f "$archive"
87
87
  retry=1
88
88
  else
89
- "$rvm_scripts_path/log" "error" "There was an error, please check $rvm_ruby_log_path/*.error.log. Next we'll try to fetch via http."
89
+ "$rvm_path/scripts/log" "error" "There was an error, please check $rvm_ruby_log_path/*.error.log. Next we'll try to fetch via http."
90
90
  try_http=1
91
91
  fi
92
92
 
@@ -94,7 +94,7 @@ if [[ $download -gt 0 ]] ; then
94
94
  eval $fetch_command "$url"
95
95
  result=$?
96
96
  if [[ $result -gt 0 ]] ; then
97
- "$rvm_scripts_path/log" "error" "There was an error, please check $rvm_ruby_log_path/*.error.log"
97
+ "$rvm_path/scripts/log" "error" "There was an error, please check $rvm_ruby_log_path/*.error.log"
98
98
  else
99
99
  record_md5
100
100
  fi
@@ -104,7 +104,7 @@ if [[ $download -gt 0 ]] ; then
104
104
  eval $fetch_command "$http_url"
105
105
  result=$?
106
106
  if [[ $result -gt 0 ]] ; then
107
- "$rvm_scripts_path/log" "error" "There was an error, please check $rvm_ruby_log_path/*.error.log"
107
+ "$rvm_path/scripts/log" "error" "There was an error, please check $rvm_ruby_log_path/*.error.log"
108
108
  else
109
109
  record_md5
110
110
  fi
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- source "$rvm_scripts_path/base"
3
+ source "$rvm_path/scripts/base"
4
4
 
5
5
  rvm_ruby_gem_home="${rvm_ruby_gem_home:-$GEM_HOME}"
6
6
 
@@ -25,56 +25,91 @@ usage() {
25
25
 
26
26
  gemset_update() {
27
27
  if [[ -z "$rvm_ruby_strings" ]]; then
28
- "$rvm_scripts_path/log" "info" "Running gem update for all rubies and gemsets."
28
+ "$rvm_path/scripts/log" "info" "Running gem update for all rubies and gemsets."
29
29
 
30
- rvm_ruby_strings="$(builtin cd "$rvm_gems_path" ; find * -type d -maxdepth 0 -print 2>/dev/null | grep -v '^\(doc\|cache\|@\|system\)' | \tr '\n' ',')"
30
+ rvm_ruby_strings="$(builtin cd "$rvm_gems_path" ; find . -maxdepth 1 -mindepth 1 -type d -print 2>/dev/null | grep -v '^\(doc\|cache\|@\|system\)' | \tr '\n' ',')"
31
31
  rvm_ruby_strings="${rvm_ruby_strings/%,}"
32
+ rvm_ruby_strings="${rvm_ruby_strings//.\/}"
32
33
  else
33
- "$rvm_scripts_path/log" "info" "Running gem update for the specified rubies."
34
+ "$rvm_path/scripts/log" "info" "Running gem update for the specified rubies."
34
35
  fi
35
36
  export rvm_ruby_strings
36
- "$rvm_scripts_path/set" "gem" "update"
37
+ "$rvm_path/scripts/set" "gem" "update"
37
38
  return $?
38
39
  }
39
40
 
40
41
  gemset_globalcache() {
42
+ local gc_status globalcache_enabled directories directory_name full_directory_path directory_name
43
+
41
44
  if [[ "$1" == "enabled" ]]; then
45
+
42
46
  __rvm_using_gemset_globalcache
43
- local globalcache_enabled="$?"
44
- local gc_status="Unknown"
45
- if [[ "$globalcache_enabled" == "0" ]]; then
47
+
48
+ globalcache_enabled=$?
49
+ gc_status="Unknown"
50
+
51
+ if [[ $globalcache_enabled -eq 0 ]]; then
46
52
  gc_status="Enabled"
47
53
  else
48
54
  gc_status="Disabled"
49
55
  fi
50
- "$rvm_scripts_path/log" "info" "Gemset global cache is currently: $gc_status"
56
+
57
+ "$rvm_path/scripts/log" "info" "Gemset global cache is currently: $gc_status"
58
+
51
59
  return "$globalcache_enabled"
60
+
52
61
  elif [[ "$1" == "disable" ]]; then
53
- "$rvm_scripts_path/log" "info" "Removing the global cache (note: this will empty the caches)"
54
- for directory_name in $(builtin cd "$rvm_gems_path" ; find * -type d -maxdepth 0 -print); do
62
+
63
+ "$rvm_path/scripts/log" "info" "Removing the global cache (note: this will empty the caches)"
64
+
65
+ directories=($(builtin cd "$rvm_gems_path" ; find . -maxdepth 1 -mindepth 1 -type d -print))
66
+
67
+ for directory_name in "${directories[@]//.\/}"; do
68
+
55
69
  current_cache_path="$rvm_gems_path/$directory_name/cache"
70
+
56
71
  if [[ -L "$current_cache_path" && "$(readlink "$current_cache_path")" == "$rvm_gems_cache_path" ]]; then
57
- "$rvm_scripts_path/log" "info" "Reverting the gem cache for $directory_name to an empty directory."
72
+
73
+ "$rvm_path/scripts/log" "info" "Reverting the gem cache for $directory_name to an empty directory."
74
+
58
75
  rm -f "$current_cache_path" 2>/dev/null
76
+
59
77
  mkdir -p "$current_cache_path" 2>/dev/null
60
78
  fi
61
- done; unset full_directory_path directory_name
62
- "$rvm_scripts_path/db" "$rvm_config_path/user" "use_gemset_globalcache" "delete"
79
+ done
80
+
81
+ "$rvm_path/scripts/db" "$rvm_config_path/user" "use_gemset_globalcache" "delete"
82
+
63
83
  elif [[ "$1" == "enable" ]]; then
64
- "$rvm_scripts_path/log" "info" "Enabling global cache for gems."
84
+
85
+ "$rvm_path/scripts/log" "info" "Enabling global cache for gems."
86
+
65
87
  mkdir -p "$rvm_gems_cache_path"
66
- for directory_name in $(builtin cd "$rvm_gems_path" ; find * -type d -maxdepth 0 -print); do
88
+
89
+ directories=($(builtin cd "$rvm_gems_path" ; find . -maxdepth 1 -mindepth 1 -type d -print))
90
+
91
+ for directory_name in "${directories[@]//.\/}" ; do
92
+
67
93
  current_cache_path="$rvm_gems_path/$directory_name/cache"
94
+
68
95
  if [[ -d "$current_cache_path" && ! -L "$current_cache_path" ]]; then
69
- "$rvm_scripts_path/log" "info" "Moving the gem cache for $directory_name to the global cache."
96
+
97
+ "$rvm_path/scripts/log" "info" "Moving the gem cache for $directory_name to the global cache."
98
+
70
99
  mv "$current_cache_path/"*.gem "$rvm_gems_cache_path/" 2>/dev/null
100
+
71
101
  rm -rf "$current_cache_path"
102
+
72
103
  ln -nfs "$rvm_gems_cache_path" "$current_cache_path"
73
104
  fi
74
- done; unset full_directory_path directory_name
75
- "$rvm_scripts_path/db" "$rvm_config_path/user" "use_gemset_globalcache" "true"
105
+
106
+ done
107
+
108
+ "$rvm_path/scripts/db" "$rvm_config_path/user" "use_gemset_globalcache" "true"
109
+
76
110
  else
77
111
  printf "
112
+
78
113
  Usage:
79
114
 
80
115
  rvm gemset globalcache {enable,disable}
@@ -87,7 +122,7 @@ gemset_globalcache() {
87
122
  }
88
123
 
89
124
  gemset_name() {
90
- gemset_dir | awk -F${rvm_gemset_separator} '{print $2}'
125
+ gemset_dir | awk -F${rvm_gemset_separator:-"@"} '{print $2}'
91
126
  return $?
92
127
  }
93
128
 
@@ -97,53 +132,66 @@ gemset_dir() {
97
132
  }
98
133
 
99
134
  gemset_create() {
100
- local gem_home=""
101
- local gemset=""
102
- local prefix=$(echo $rvm_ruby_gem_home | sed 's/'${rvm_gemset_separator}'.*$//')
135
+ local gem_home gemset gemsets prefix
103
136
 
104
- for gemset in $(echo $gems_args) ; do
137
+ prefix=$(echo $rvm_ruby_gem_home | sed 's/'${rvm_gemset_separator:-"@"}'.*$//')
105
138
 
106
- if [[ "$gemset" == *"${rvm_gemset_separator}"* ]]; then
107
- "$rvm_scripts_path/log" "error" "Can't do that, it contains a \"${rvm_gemset_separator}\"."
139
+ gemsets=(${args[@]})
140
+
141
+ for gemset in "${gemsets[@]}" ; do
142
+
143
+ if [[ "$gemset" == *"${rvm_gemset_separator:-"@"}"* ]]; then
144
+ "$rvm_path/scripts/log" "error" "Can't do that, it contains a \"${rvm_gemset_separator:-"@"}\"."
108
145
  continue
109
146
  fi
110
147
 
111
- gem_home="${prefix}${rvm_gemset_separator}${gemset}"
148
+ gem_home="${prefix}${rvm_gemset_separator:-"@"}${gemset}"
112
149
 
113
- [[ ! -d "$gem_home" ]] && mkdir -p "$gem_home"
150
+ if [[ ! -d "$gem_home" ]] ; then
151
+ mkdir -p "$gem_home"
152
+ fi
114
153
 
115
154
  # When the globalcache is enabled, we need to ensure we setup the cache directory correctly.
116
155
  if __rvm_using_gemset_globalcache ; then
156
+
117
157
  if [[ -d "$gem_home/cache" && ! -L "$gem_home/cache" ]]; then
158
+
118
159
  mv "$gem_home/cache"/*.gem "$rvm_gems_cache_path/" 2>/dev/null
160
+
119
161
  rm -rf "$gem_home/cache"
120
162
  fi
163
+
121
164
  ln -nfs "$rvm_gems_cache_path" "$gem_home/cache"
122
165
  fi
123
166
 
124
- "$rvm_scripts_path/log" "info" "'$gemset' gemset created ($gem_home)."
167
+ "$rvm_path/scripts/log" "info" "'$gemset' gemset created ($gem_home)."
125
168
  done
126
169
 
127
170
  return 0
128
171
  }
129
172
 
130
173
  gemset_list() {
131
- rvm_gems_path="${rvm_gems_path:-""}"
132
- rvm_ruby_string="${rvm_ruby_string:-""}"
133
174
 
134
175
  if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select ; fi
135
176
 
136
- "$rvm_scripts_path/log" "info" "gemsets for $rvm_ruby_string (found in $rvm_gems_path/$rvm_ruby_string)\n"
177
+ "$rvm_path/scripts/log" "info" \
178
+ "\ngemsets for $rvm_ruby_string (found in $rvm_gems_path/$rvm_ruby_string)"
179
+
180
+ if [[ -n "${rvm_gems_path:-""}" ]] ; then
181
+
182
+ if [[ -n "${rvm_ruby_string:-""}" ]] ; then
183
+
184
+ ls "${rvm_gems_path}/" | awk -F"${rvm_gemset_separator:-"@"}" "/${rvm_ruby_string}${rvm_gemset_separator:-"@"}/{print \$2}" 2>/dev/null
137
185
 
138
- if [[ -n "$rvm_gems_path" ]] ; then
139
- if [[ -n "$rvm_ruby_string" ]] ; then
140
- ls "${rvm_gems_path}/" | awk -F"${rvm_gemset_separator}" "/${rvm_ruby_string}${rvm_gemset_separator}/{print \$2}" 2>/dev/null
141
186
  else
142
- "$rvm_scripts_path/log" "error" "\$rvm_ruby_string is not set!"
187
+ "$rvm_path/scripts/log" "error" \
188
+ "\$rvm_ruby_string is not set!"
143
189
  return 1
144
190
  fi
191
+
145
192
  else
146
- "$rvm_scripts_path/log" "error" "\$rvm_gems_path is not set!"
193
+ "$rvm_path/scripts/log" "error" \
194
+ "\$rvm_gems_path is not set!"
147
195
  return 1
148
196
  fi
149
197
  printf "\n"
@@ -152,60 +200,99 @@ gemset_list() {
152
200
  }
153
201
 
154
202
  gemset_delete() {
203
+
155
204
  if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select ; fi
156
205
 
157
206
  if [[ -n "$rvm_gemset_name" ]] ; then
158
- gemdir="$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator}$rvm_gemset_name"
159
- if [[ -d "$gemdir" ]] && [[ "$gemdir" != '/' ]] && [[ ! -z "$rvm_force_flag" ]] ; then
160
- rm -rf "$gemdir"
207
+
208
+ gemdir="$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator:-"@"}$rvm_gemset_name"
209
+
210
+ if [[ -d "$gemdir" && "$gemdir" != '/' && ${rvm_force_flag:-0} -gt 0 ]] ; then
211
+
212
+ rm -rf "$gemdir"
213
+
161
214
  elif [[ -d "$gemdir" ]] ; then
162
- "$rvm_scripts_path/log" "warn" "Are you SURE you wish to remove the entire gemset directory '$rvm_gemset_name' ($gemdir)?"
163
- echo -n "(anything other than 'yes' will cancel) > "
215
+
216
+ "$rvm_path/scripts/log" "warn" "Are you SURE you wish to remove the entire gemset directory '$rvm_gemset_name' ($gemdir)?"
217
+
218
+ printf "(anything other than 'yes' will cancel) > "
164
219
 
165
220
  read response
166
221
 
167
222
  if [[ "yes" = "$response" ]] ; then
168
- rm -f $gemdir/cache 2>/dev/null
169
- rm -rf $gemdir
223
+
224
+ if [[ -L "$gemdir/cache" ]] ; then
225
+ rm -f "$gemdir/cache"
226
+ fi
227
+
228
+ rm -rf "$gemdir"
229
+
170
230
  else
171
- "$rvm_scripts_path/log" "info" "Not doing anything, phew... close call that one eh?"
231
+ "$rvm_path/scripts/log" "info" \
232
+ "Not doing anything, phew... close call that one eh?"
172
233
  fi
234
+
173
235
  else
174
- "$rvm_scripts_path/log" "info" "$gemdir already does not exist."
236
+ "$rvm_path/scripts/log" "info" \
237
+ "$gemdir already does not exist."
175
238
  fi
239
+
176
240
  else
177
- "$rvm_scripts_path/log" "error" "A gemset name must be specified in order to delete a gems."
241
+ "$rvm_path/scripts/log" "error" \
242
+ "A gemset name must be specified in order to delete a gems."
178
243
  return 1
179
244
  fi
245
+
180
246
  return 0
181
247
  }
182
248
 
183
249
  gemset_empty() {
184
- if [[ -z "$rvm_ruby_gem_home" ]] ; then __rvm_select ; fi
250
+
251
+ local gemdir
252
+
253
+ if [[ -z "${rvm_ruby_gem_home:-""}" ]] ; then __rvm_select ; fi
254
+
185
255
  gemdir="$rvm_ruby_gem_home"
186
- if [[ -d "$gemdir" ]] && [[ "$gemdir" != '/' ]] && [[ ! -z "$rvm_force_flag" ]] ; then
256
+
257
+ if [[ -d "$gemdir" && "$gemdir" != '/' && ${rvm_force_flag:-0} -gt 0 ]] ; then
258
+
187
259
  builtin cd "$gemdir" && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/*
260
+
188
261
  elif [[ -d "$gemdir" ]] ; then
189
- "$rvm_scripts_path/log" "warn" "Are you SURE you wish to remove the installed gemset for gemset '$(basename "$gemdir")' ($gemdir)?"
262
+
263
+ "$rvm_path/scripts/log" "warn" \
264
+ "Are you SURE you wish to remove the installed gemset for gemset '$(basename "$gemdir")' ($gemdir)?"
265
+
190
266
  echo -n "(anything other than 'yes' will cancel) > "
267
+
191
268
  read response
269
+
192
270
  if [[ "yes" = "$response" ]] ; then
271
+
193
272
  builtin cd "$gemdir" && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/*
273
+
194
274
  else
195
- "$rvm_scripts_path/log" "info" "Not doing anything, phew... close call that one eh?"
275
+ "$rvm_path/scripts/log" "info" \
276
+ "Not doing anything, phew... close call that one eh?"
196
277
  fi
278
+
197
279
  else
198
- "$rvm_scripts_path/log" "info" "$gemdir already does not exist."
199
- fi ; unset gemdir
280
+ "$rvm_path/scripts/log" "info" \
281
+ "$gemdir already does not exist."
282
+ fi
283
+
284
+ return 0
200
285
  }
201
286
 
202
287
  # Migrate gemsets from ruby X to ruby Y
203
288
  gemset_copy() {
204
- local source_ruby="${args[1]:-""}"
205
- local destination_ruby="${args[2]:-""}"
289
+ local source_ruby destination_ruby source_path destination_path
290
+
291
+ source_ruby="${args[1]:-""}"
292
+ destination_ruby="${args[2]:-""}"
206
293
 
207
294
  if [[ -z "$destination_ruby" || -z "$source_ruby" ]] ; then
208
- "$rvm_scripts_path/log" "error" "Source and destination must be specified: 'rvm gemset copy X Y'"
295
+ "$rvm_path/scripts/log" "error" "Source and destination must be specified: 'rvm gemset copy X Y'"
209
296
  return 1
210
297
  fi
211
298
 
@@ -215,75 +302,104 @@ gemset_copy() {
215
302
  # rvm gemset copy gemseta gemsetb # Currenty Ruby, gemseta exists.
216
303
  # rvm gemset copy gemseta 1.8.7@gemsetb # Currenty Ruby@gemseta, current ruby@gemseta exists.
217
304
 
218
- local source_path="$(rvm_silence_logging=1 rvm "$source_ruby" gem env gemdir)"
219
- local destination_path="$(rvm_silence_logging=1 rvm "$destination_ruby" gem env gemdir)"
305
+ source_path="$(rvm_silence_logging=1 rvm "$source_ruby" gem env gemdir)"
306
+
307
+ destination_path="$(rvm_silence_logging=1 rvm "$destination_ruby" gem env gemdir)"
220
308
 
221
309
  if [[ -z "$source_path" || ! -d "$source_path" ]]; then
222
- "$rvm_scripts_path/log" "error" "Unable to expand '$source_ruby' or directory does not exist."
310
+ "$rvm_path/scripts/log" "error" "Unable to expand '$source_ruby' or directory does not exist."
223
311
  return 1
224
312
  fi
225
313
 
226
314
  if [[ -z "$destination_path" ]]; then
227
- "$rvm_scripts_path/log" "error" "Unable to expand '$destination_ruby'"
315
+ "$rvm_path/scripts/log" "error" "Unable to expand '$destination_ruby'"
228
316
  return 1
229
317
  fi
230
318
 
231
319
  if [[ -d "$source_path" ]] ; then
232
320
 
233
- "$rvm_scripts_path/log" "info" "Copying gemset from $source_ruby to $destination_ruby"
321
+ "$rvm_path/scripts/log" "info" "Copying gemset from $source_ruby to $destination_ruby"
234
322
 
235
323
  for dir in bin doc gems specifications cache ; do
324
+
236
325
  mkdir -p "$destination_path/$dir"
237
- cp -Rf "$source_path/$dir" "$destination_path/"
326
+
327
+ if [[ -d "$source_ruby/$dir" ]] ; then
328
+ cp -Rf "$source_path/$dir" "$destination_path/"
329
+
330
+ elif [[ -L "$source_path/$dir" ]] ; then
331
+ cp "$source_path/$dir" "$destination_path/$dir"
332
+ fi
333
+
238
334
  done
239
335
 
240
- "$rvm_scripts_path/log" "info" "Making gemset for $destination_ruby pristine."
336
+ "$rvm_path/scripts/log" "info" \
337
+ "Making gemset for $destination_ruby pristine."
241
338
 
242
339
  __rvm_run_with_env "gemset.pristine" "$destination_ruby" "rvm gemset pristine"
340
+
243
341
  else
244
- "$rvm_scripts_path/log" "error" "Gems directory does not exist for $source_path ($source_path)"
342
+ "$rvm_path/scripts/log" "error" \
343
+ "Gems directory does not exist for $source_path ($source_path)"
245
344
  return 1
246
345
  fi
247
346
  }
248
347
 
249
348
  gemset_export() {
349
+ local gems name file_name version versions
350
+
250
351
  rvm_file_name="${rvm_file_name:-${gems_args// }}"
251
352
 
252
- if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
353
+ if [[ -n "$rvm_ruby_gem_home" ]] ; then
253
354
  export GEM_HOME="$rvm_ruby_gem_home"
254
- export GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator}global/bin"
355
+ export GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator:-"@"}global/bin"
255
356
  export BUNDLE_PATH="$rvm_ruby_gem_home"
256
357
  fi
257
358
 
258
359
  if [[ -z "$rvm_file_name" ]] ; then
259
- if [[ ! -z "$rvm_gemset_name" ]] ; then
360
+
361
+ if [[ -n "$rvm_gemset_name" ]] ; then
260
362
  rvm_file_name="$rvm_gemset_name.gems"
363
+
261
364
  else
262
365
  rvm_file_name="default.gems"
263
366
  fi
264
367
  fi
265
368
 
266
- "$rvm_scripts_path/log" "info" "Exporting current environments gemset to $rvm_file_name"
369
+ "$rvm_path/scripts/log" "info" \
370
+ "Exporting current environments gemset to $rvm_file_name"
267
371
 
268
372
  touch "$rvm_file_name"
373
+
269
374
  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"
270
- for gem in $(gem list | sed 's#[\(|\)]##g' | sed 's#, #,#g' | tr ' ' ';') ; do
375
+
376
+ gems=($(gem list | sed 's#[\(|\)]##g' | sed 's#, #,#g' | tr ' ' ';'))
377
+
378
+ for gem in "${gems[@]}" ; do
379
+
271
380
  name="${gem/;*/}"
272
- if [[ -z "$rvm_latest_flag" ]] ; then
381
+
382
+ if [[ ${rvm_latest_flag:-0} -eq 0 ]] ; then
383
+
273
384
  versions="${gem/*;/}" ; versions="${versions//,/ }"
385
+
274
386
  for version in $versions ; do
275
387
  echo "$name -v$version" >> $rvm_file_name
276
388
  done ; unset version versions
389
+
277
390
  else
278
391
  echo "$name" >> $rvm_file_name
279
- fi ; unset name
280
- done ; unset file_name
392
+ fi
393
+ done
394
+
395
+ return 0
281
396
  }
282
397
 
283
398
  gemset_import() {
284
- if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
399
+
400
+ if [[ -n "${rvm_ruby_gem_home:-""}" ]] ; then
285
401
  export GEM_HOME="$rvm_ruby_gem_home"
286
- export GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator}global/bin"
402
+ export GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator:-"@"}global/bin"
287
403
  export BUNDLE_PATH="$rvm_ruby_gem_home"
288
404
  fi
289
405
 
@@ -291,56 +407,71 @@ gemset_import() {
291
407
 
292
408
  if [[ -s "${rvm_file_name%.gems*}.gems" ]] ; then
293
409
  rvm_file_name="${rvm_file_name%.gems*}.gems"
410
+
294
411
  elif [[ -s "${rvm_gemset_name}.gems" ]] ; then
295
412
  rvm_file_name="${rvm_gemset_name}.gems"
413
+
296
414
  elif [[ -s "default.gems" ]] ; then
297
415
  rvm_file_name="default.gems"
416
+
298
417
  elif [[ -s "system.gems" ]] ; then
299
418
  rvm_file_name="system.gems"
419
+
300
420
  elif [[ -s ".gems" ]] ; then
301
421
  rvm_file_name=".gems"
422
+
302
423
  else
303
- "$rvm_scripts_path/log" "error" "No *.gems file found."
424
+ "$rvm_path/scripts/log" "error" "No *.gems file found."
304
425
  return 1
305
426
  fi
306
427
 
307
428
  mkdir -p "$rvm_gems_cache_path" # Ensure the base cache dir is initialized.
308
429
 
309
430
  if [[ -s "$rvm_file_name" ]] ; then
431
+
310
432
  echo "Importing $rvm_file_name file..."
311
433
 
312
- rvm_ruby_gem_list=$(builtin cd "$rvm_ruby_gem_home/specifications/" ; find * -type f -maxdepth 0 -print 2> /dev/null | sed -e 's#.gems.*$##' 2> /dev/null)
434
+ rvm_ruby_gem_list=$(builtin cd "$rvm_ruby_gem_home/specifications/" ; find . -maxdepth 1 -mindepth 1 -type f -print 2> /dev/null | sed -e 's#.gems.*$##' 2> /dev/null)
435
+ rvm_ruby_gem_list="${rvm_ruby_gem_list//.\/}"
313
436
 
314
437
  while read -r line
315
438
  do # Keep this on 2nd line :(
439
+
316
440
  if [[ -n "${line// /}" ]] ; then
317
441
  gems_args="$line" ; gem_install
318
442
  fi
443
+
319
444
  done < <(awk '/^[^#]+/{print}' "${rvm_file_name}")
445
+
320
446
  else
321
- "$rvm_scripts_path/log" "error" "${rvm_file_name} does not exist to import from."
447
+ "$rvm_path/scripts/log" "error" "${rvm_file_name} does not exist to import from."
322
448
  fi
323
449
  }
324
450
 
325
451
  __rvm_parse_gems_args() {
326
452
 
327
453
  gem="${gems_args/;*}" ; gem_prefix=""
454
+
328
455
  if echo "$gems_args" | grep -q ';' ; then
329
456
  gem_prefix="${gems_args/*;}"
330
457
  fi
331
458
 
332
- if "$rvm_scripts_path/match" "$gem" ".gem$" ; then
459
+ if "$rvm_path/scripts/match" "$gem" ".gem$" ; then
333
460
  gem_name="$(basename "${gem/.gem/}" | awk -F'-' '{$NF=NULL;print}')"
334
461
  gem_version="$(basename "${gem/.gem/}" | awk -F'-' '{print $NF}' )"
335
462
  gem_postfix="$(basename "${gem/*.gem/}")"
463
+
336
464
  else
337
465
  gem_name="${gem/ */}"
338
- if "$rvm_scripts_path/match" "$gem" "--version" ; then
466
+
467
+ if "$rvm_path/scripts/match" "$gem" "--version" ; then
339
468
  gem_version="$(echo "$gem" | sed -e 's#.*--version[=]*[ ]*##' | awk '{print $1}')"
340
469
  gem_postfix="$(echo "$gem" | sed -e "s#${gem_name/ /}##" -e "s#--version[=]*[ ]*${gem_version/ /}##")"
341
- elif "$rvm_scripts_path/match" "$gem" "-v" ; then
470
+
471
+ elif "$rvm_path/scripts/match" "$gem" "-v" ; then
342
472
  gem_version="$(echo "$gem" | sed -e 's#.*-v[=]*[ ]*##' | awk '{print $1}')"
343
473
  gem_postfix="$(echo "$gem" | sed -e "s#${gem_name/ /}##" -e "s#-v[=]*[ ]*${gem_version/ /}##")"
474
+
344
475
  else
345
476
  unset gem_version # no version
346
477
  fi
@@ -348,10 +479,13 @@ __rvm_parse_gems_args() {
348
479
 
349
480
  if [[ -s "$gem" ]] ; then
350
481
  gem_file_name="$gem"
351
- elif "$rvm_scripts_path/match" "$gem" ".gem$" ; then
482
+
483
+ elif "$rvm_path/scripts/match" "$gem" ".gem$" ; then
352
484
  gem_file_name="$gem"
485
+
353
486
  elif [[ -z "${gem_version/ /}" ]] ; then
354
487
  gem_file_name="${gem_name/ /}*.gem"
488
+
355
489
  else # version
356
490
  gem_file_name="${gem_name/ /}-${gem_version/ /}.gem"
357
491
  fi
@@ -359,14 +493,20 @@ __rvm_parse_gems_args() {
359
493
 
360
494
  # Install a gem
361
495
  gem_install() {
362
- # First we parse the gem args to pick apart the pieces.
363
496
 
497
+ local gem gem_prefix gem_name gem_version gem_file_name gem_postfix cache_file gem_file_name gem_string gem_action
498
+ result=0
499
+
500
+ # First we parse the gem args to pick apart the pieces.
364
501
  __rvm_parse_gems_args
365
502
 
366
503
  # Now we determine if a .gem cache file is already installed
367
- if [[ -z "$rvm_force_flag" ]] && [[ -f "${rvm_ruby_gem_home}/specifications/$(basename "$gem_file_name")spec" ]] ; then
368
- unset gem
369
- "$rvm_scripts_path/log" "info" "$gem_name $gem_version exists, skipping (--force to re-install)"
504
+ if [[ ${rvm_force_flag:-0} -eq 0 && -f "${rvm_ruby_gem_home}/specifications/$(basename "$gem_file_name")spec" ]] ; then
505
+ gem=""
506
+
507
+ "$rvm_path/scripts/log" "info" \
508
+ "$gem_name $gem_version exists, skipping (--force to re-install)"
509
+
370
510
  else
371
511
  if [[ -s "$gem" ]] ; then
372
512
  cache_file="$gem"
@@ -375,7 +515,8 @@ gem_install() {
375
515
  cache_file="$(__rvm_current_gemcache_dir)/${gem_file_name}"
376
516
 
377
517
  else
378
- cache_file="${cache_file:-$(builtin cd "$(__rvm_current_gemcache_dir)/${gem_file_name}" ; find * -type f -maxdepth 0 -print 2> /dev/null | sort | head -n1)}"
518
+ cache_file="${cache_file:-$( find "$(__rvm_current_gemcache_dir)/${gem_file_name}" -maxdepth 1 -mindepth 1 -type f -print 2> /dev/null | sort | head -n1)}"
519
+ cache_file="${cache_file//.\/}"
379
520
  fi
380
521
 
381
522
  if [[ ! -s "$cache_file" ]] ; then
@@ -395,10 +536,10 @@ gem_install() {
395
536
 
396
537
  gem_string="$(echo "$gem_file_name" | sed 's#\.gem$##')"
397
538
 
398
- if [[ -z "$rvm_force_flag" ]] && [[ -s "${rvm_ruby_gem_home}/specifications/$(basename $gem_file_name)spec" ]] ; then
539
+ if [[ ${rvm_force_flag:-0} -eq 0 && -s "${rvm_ruby_gem_home}/specifications/$(basename $gem_file_name)spec" ]] ; then
399
540
  unset gem # already installed, not forcing reinstall.
400
541
 
401
- "$rvm_scripts_path/log" "info" "$gem_name $gem_version exists, skipping (--force to re-install)"
542
+ "$rvm_path/scripts/log" "info" "$gem_name $gem_version exists, skipping (--force to re-install)"
402
543
 
403
544
  else
404
545
  if [[ -s "$(__rvm_current_gemcache_dir)/$(basename $gem_file_name)" ]] ; then
@@ -416,102 +557,156 @@ gem_install() {
416
557
  fi
417
558
 
418
559
  # If $gem is still set, go forward with the install.
419
- if [[ ! -z "$gem" ]] ; then
560
+ if [[ -n "$gem" ]] ; then
561
+
420
562
  # TODO: Set vars if fourth field is non-empty (means that there are conditional statements to execute in the gem install line.
421
563
  if [[ "rvm_make_flags_flag" -eq 1 ]] ; then __rvm_make_flags ; fi
422
564
 
423
- if [[ ! -z "$rvm_ruby_gem_home" ]] && [[ "$rvm_ruby_gem_home" != "$rvm_gems_path" ]] ; then
424
- command="GEM_HOME='$rvm_ruby_gem_home' GEM_PATH='$rvm_ruby_gem_home/bin:$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}global/bin' BUNDLE_PATH='${rvm_ruby_gem_home}' ${gem_prefix} command gem install $gems_args $rvm_gem_options $gem_postfix $vars"
565
+ if [[ -n "$rvm_ruby_gem_home" && "$rvm_ruby_gem_home" != "$rvm_gems_path" ]] ; then
566
+
567
+ command="GEM_HOME='$rvm_ruby_gem_home' GEM_PATH='$rvm_ruby_gem_home/bin:$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator:-"@"}global/bin' BUNDLE_PATH='${rvm_ruby_gem_home}' ${gem_prefix} command gem install $gems_args $rvm_gem_options $gem_postfix $vars"
568
+
425
569
  else
570
+
426
571
  #--ignore-dependencies
427
572
  command="$gem_prefix command gem install --ignore-dependencies $gems_args $rvm_gem_options -q $gem $gem_postfix $vars"
573
+
428
574
  fi
575
+
429
576
  __rvm_run "gem.install" "$command" "installing ${gem_name} ${gem_version}..."
430
577
  result=$?
578
+
431
579
  if [[ $result -eq 0 ]] ; then
432
- "$rvm_scripts_path/log" "info" "$gem_name $gem_version installed ( output logged to: $rvm_path/log/$rvm_ruby_string/gem.install.log )"
580
+
581
+ "$rvm_path/scripts/log" "info" \
582
+ "$gem_name $gem_version installed ( output logged to: $rvm_path/log/$rvm_ruby_string/gem.install.log )"
583
+
433
584
  else
434
- "$rvm_scripts_path/log" "error" "$gem_name $gem_version failed to install ( output logged to: $rvm_path/log/$rvm_ruby_string/gem.install.error.log )"
585
+
586
+ "$rvm_path/scripts/log" "error" \
587
+ "$gem_name $gem_version failed to install ( output logged to: $rvm_path/log/$rvm_ruby_string/gem.install.error.log )"
588
+
435
589
  fi
436
- fi ; unset gem gem_prefix gem_name gem_version gem_file_name gem_postfix cache_file gem_file_name gem_string gem_action
590
+ fi
437
591
 
438
592
  return $result
439
593
  }
440
594
 
441
595
  # Output the user's current gem directory.
442
596
  gemset_info() {
443
- if [[ "$rvm_user_flag" -eq 1 ]] ; then
597
+ if [[ ${rvm_user_flag:-0} -eq 1 ]] ; then
444
598
  echo $(rvm system ; gem env | grep "\- $HOME" | awk '{print $NF}')
445
- elif [[ "$rvm_system_flag" -eq 1 ]] ; then
599
+
600
+ elif [[ ${rvm_system_flag:-0} -eq 1 ]] ; then
446
601
  echo $(rvm system ; gem env $action system)
447
- elif [[ ! -z "$rvm_ruby_string" ]] ; then
602
+
603
+ elif [[ -n "${rvm_ruby_string:-""}" ]] ; then
448
604
  echo $(rvm "$rvm_ruby_string" ; gem env $action)
449
- elif [[ ! -z "$GEM_HOME" ]] ; then
605
+
606
+ elif [[ -n "${GEM_HOME:-""}" ]] ; then
450
607
  echo "$GEM_HOME"
608
+
451
609
  else
452
610
  gem env $action
453
611
  fi
612
+
454
613
  return $?
455
614
  }
456
615
 
457
616
  gemset_prune() {
617
+ local temporary_cache_path live_cache_path gemset_name version versions cached_gem_name cached_file_path
618
+
458
619
  temporary_cache_path="$GEM_HOME/temporary-cache"
620
+
459
621
  live_cache_path="$GEM_HOME/cache"
622
+
460
623
  mkdir -p "$temporary_cache_path"
461
- "$rvm_scripts_path/log" "info" "Moving active gems into temporary cache..."
462
- while read -r used_gem; do
624
+
625
+ "$rvm_path/scripts/log" "info" \
626
+ "Moving active gems into temporary cache..."
627
+
628
+ while read -r used_gem
629
+ do
463
630
  gem_name="$(echo "$used_gem" | sed -e 's/ .*//')"
631
+
464
632
  versions="$(echo "${used_gem//, / }" | sed -e 's/.* (//' -e 's/)//')"
633
+
465
634
  for version in $versions; do
635
+
466
636
  cached_gem_name="${gem_name}-${version}.gem"
637
+
467
638
  cached_file_path="${live_cache_path}/${cached_gem_name}"
639
+
468
640
  if [[ -f "$cached_file_path" ]]; then
469
641
  mv "$cached_file_path" "${temporary_cache_path}/${cached_gem_name}"
470
642
  fi
471
643
  done
472
644
  done < <(gem list --versions)
473
- "$rvm_scripts_path/log" "info" "Removing live cache and restoring temporary cache..."
645
+
646
+ "$rvm_path/scripts/log" "info" \
647
+ "Removing live cache and restoring temporary cache..."
648
+
474
649
  # Switch the cache back.
475
650
  rm -rf "$live_cache_path"
651
+
476
652
  mv "$temporary_cache_path" "$live_cache_path"
653
+
477
654
  return 0
478
655
  }
479
656
 
480
657
  gemset_pristine() {
481
658
  if command -v gem > /dev/null ; then
659
+
482
660
  gem pristine --all
661
+
483
662
  return $?
663
+
484
664
  else
485
- "$rvm_scripts_path/log" "error" "'gem' command not found in PATH"
665
+
666
+ "$rvm_path/scripts/log" "error" \
667
+ "'gem' command not found in PATH"
668
+
486
669
  return 1
487
670
  fi
488
671
  }
489
672
 
490
673
  # Loads the default gemsets for the current interpreter and gemset.
491
674
  gemset_initial() {
492
- "$rvm_scripts_path/log" "info" "Importing initial gemsets for $(__rvm_environment_identifier)."
493
675
 
494
- mkdir -p "$rvm_gemsets_path/${rvm_ruby_string//-//}" 2>/dev/null
676
+ "$rvm_path/scripts/log" "info" "Importing initial gemsets for $(__rvm_environment_identifier)."
677
+
678
+ mkdir -p "$rvm_path/gemsets/${rvm_ruby_string//-//}" 2>/dev/null
679
+
680
+ for gemsets_path in $(__rvm_ruby_string_paths_under "$rvm_path/gemsets") ; do
495
681
 
496
- for gemsets_path in $(__rvm_ruby_string_paths_under "$rvm_gemsets_path") ; do
497
682
  # TODO: This can be condensed.
498
683
  if [[ -d "$gemsets_path" ]] ; then
499
684
 
500
685
  if [[ -n "$rvm_gemset_name" && -s "${gemsets_path}/${rvm_gemset_name}.gems" ]] ; then
501
- ( rvm --create use "$rvm_ruby_string" ; "$rvm_scripts_path/gemsets" import "${gemsets_path}/${rvm_gemset_name}.gems" )
686
+ (
687
+ rvm --create "$rvm_ruby_string"
688
+ "$rvm_path/scripts/gemsets" import "${gemsets_path}/${rvm_gemset_name}.gems"
689
+ )
502
690
  fi
503
691
 
504
692
  if [[ -s "${gemsets_path}/default.gems" ]] ; then
505
- ( rvm --create use "$rvm_ruby_string" ; "$rvm_scripts_path/gemsets" import "$gemsets_path/default.gems" )
693
+ (
694
+ rvm --create "$rvm_ruby_string"
695
+ "$rvm_path/scripts/gemsets" import "$gemsets_path/default.gems"
696
+ )
506
697
  fi
507
698
 
508
699
  if [[ -s "${gemsets_path}/global.gems" ]] ; then
509
- ( rvm --create use "$rvm_ruby_string@global" ; "$rvm_scripts_path/gemsets" import "${gemsets_path}/global.gems" )
700
+ (
701
+ rvm --create "$rvm_ruby_string@global"
702
+ "$rvm_path/scripts/gemsets" import "${gemsets_path}/global.gems"
703
+ )
510
704
  fi
511
705
  fi
512
706
  done
513
707
 
514
- "$rvm_scripts_path/log" "info" "Installation of gems for $(__rvm_environment_identifier) is complete."
708
+ "$rvm_path/scripts/log" "info" \
709
+ "Installation of gems for $(__rvm_environment_identifier) is complete."
515
710
 
516
711
  return 0
517
712
  }
@@ -519,66 +714,106 @@ gemset_initial() {
519
714
  unset GEM_PATH
520
715
 
521
716
  if ! command -v gem > /dev/null ; then
522
- "$rvm_scripts_path/log" "error" "'gem' was not found, cannot perform gem actions (Do you have an RVM ruby selected?)"
717
+ "$rvm_path/scripts/log" "error" \
718
+ "'gem' was not found, cannot perform gem actions (Do you have an RVM ruby selected?)"
523
719
  exit 1
524
720
  fi
525
721
 
526
722
  args=($*)
527
723
  action="${args[0]}"
528
- gems_args="$(echo ${args[@]:1}) " # Strip trailing / leading / extra spacing.
724
+ args=($(echo ${args[@]:1}))
725
+ gems_args="$(echo ${args[@]}) " # Strip trailing / leading / extra spacing.
529
726
 
530
727
  export rvm_gemset_name="${args[1]:-""}" # For wherever used.
531
728
  rvm_sticky_flag=1
532
729
 
533
- if [[ "import" = "$action" ]] || [[ "load" = "$action" ]] ; then
534
- if [[ -z "$rvm_ruby_strings" ]]; then
535
- gemset_import
536
- else
537
- original_env="$(__rvm_environment_identifier)"
538
- for rvm_ruby_string in $(echo "$rvm_ruby_strings" | tr "," " "); do
539
- __rvm_become
540
- gemset_import
541
- done
542
- __rvm_become "$original_env"
543
- unset original_env
730
+ if [[ -z "$rvm_ruby_string" ]] ; then
731
+ if echo "${GEM_HOME:-""}" | grep -q 'rvm' ; then
732
+ rvm_ruby_string="${GEM_HOME##*/}"
733
+ rvm_ruby_string="${rvm_ruby_string%%@*}"
544
734
  fi
545
- elif [[ "export" = "$action" ]] || [[ "dump" = "$action" ]] ; then
546
- gemset_export
547
- elif [[ "create" = "$action" ]] ; then
548
- gemset_create
549
- elif [[ "copy" = "$action" ]] ; then
550
- gemset_copy
551
- elif [[ "empty" = "$action" ]] ; then
552
- gemset_empty
553
- elif [[ "delete" = "$action" ]] ; then
554
- gemset_delete
555
- elif [[ "name" = "$action" ]] || [[ "string" = "$action" ]]; then
556
- gemset_name
557
- elif [[ "dir" = "$action" ]] ; then
558
- gemset_dir
559
- elif [[ "list" = "$action" ]] ; then
560
- gemset_list
561
- elif [[ "gemdir" = "$action" ]] || [[ "gempath" = "$action" ]] || [[ "gemhome" = "$action" ]] || [[ "home" = "$action" ]] || [[ "path" = "$action" ]] || [[ "version" = "$action" ]] ; then
562
- gemset_info
563
- elif [[ "install" = "$action" ]] ; then
564
- gem_install "$@"
565
- elif [[ "pristine" = "$action" ]] ; then
566
- gemset_pristine "$@"
567
- elif [[ "initial" = "$action" ]] ; then
568
- gemset_initial
569
- elif [[ "prune" = "$action" ]] ; then
570
- gemset_prune
571
- elif [[ "update" = "$action" ]]; then
572
- gemset_update
573
- elif [[ "globalcache" = "$action" ]]; then
574
- gemset_globalcache "$2"
575
- elif [[ "clear" = "$action" ]] ; then
576
- "$rvm_scripts_path/log" "info" "gemset cleared."
577
- exit 0
578
- elif [[ "help" = "$action" ]] ; then
579
- usage ; exit 0
580
- else
581
- usage ; exit 1
582
735
  fi
583
736
 
737
+ case "$action" in
738
+
739
+ import|load)
740
+
741
+ if [[ -z "${rvm_ruby_strings:-""}" ]]; then
742
+
743
+ gemset_import
744
+
745
+ else
746
+ original_env="$(__rvm_environment_identifier)"
747
+
748
+ for rvm_ruby_string in $(echo "$rvm_ruby_strings" | tr "," " "); do
749
+
750
+ __rvm_become
751
+
752
+ gemset_import
753
+ done
754
+
755
+ __rvm_become "$original_env"
756
+
757
+ unset original_env
758
+ fi
759
+ ;;
760
+ export|dump)
761
+ gemset_export
762
+ ;;
763
+ create)
764
+ gemset_create
765
+ ;;
766
+ copy)
767
+ gemset_copy
768
+ ;;
769
+ empty)
770
+ gemset_empty
771
+ ;;
772
+ delete)
773
+ gemset_delete
774
+ ;;
775
+ name|string)
776
+ gemset_name
777
+ ;;
778
+ dir)
779
+ gemset_dir
780
+ ;;
781
+ list)
782
+ gemset_list
783
+ ;;
784
+ gemdir|gempath|gemhome|home|path|version)
785
+ gemset_info
786
+ ;;
787
+ install)
788
+ gem_install "$@"
789
+ ;;
790
+ pristine)
791
+ gemset_pristine "$@"
792
+ ;;
793
+ initial)
794
+ gemset_initial
795
+ ;;
796
+ prune)
797
+ gemset_prune
798
+ ;;
799
+ update)
800
+ gemset_update
801
+ ;;
802
+ globalcache)
803
+ gemset_globalcache "$2"
804
+ ;;
805
+ clear)
806
+ "$rvm_path/scripts/log" "info" "gemset cleared."
807
+ exit 0
808
+ ;;
809
+ help)
810
+ usage
811
+ exit 0
812
+ ;;
813
+ *)
814
+ usage
815
+ exit 1
816
+ ;;
817
+ esac
818
+
584
819
  exit $?