rvm 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,9 +10,12 @@ usage() {
10
10
  }
11
11
 
12
12
  confirm() {
13
- printf "$1 (Y/n): "
14
13
  local confirmation_response
14
+
15
+ printf "$1 (Y/n): "
16
+
15
17
  read -r confirmation_response
18
+
16
19
  [[ -z "$confirmation_response" ]] || echo "$confirmation_response" | \grep -qi '^y'
17
20
  }
18
21
 
@@ -26,79 +29,116 @@ expand_ruby_name() {
26
29
  }
27
30
 
28
31
  migrate_rubies() {
32
+ local origin_gemset destination_gemset gemset_name migrate_ruby_name migrate_alias_name migrate_new_alias_name binaries origin_wrappers_path full_bin_path expanded_symlink linked_binary_name new_wrapper_destination
33
+
29
34
  expanded_source="$(expand_ruby_name "$source_ruby")"
30
35
  expanded_destination="$(expand_ruby_name "$destination_ruby")"
31
36
 
32
37
  if [[ -z "$expanded_source" ]]; then
33
38
  die_with_error "Could not expand source ruby '$source_ruby'"
39
+
34
40
  elif [[ -z "$expanded_destination" ]]; then
35
41
  die_with_error "Could not expand destination ruby '$destination_ruby'"
42
+
36
43
  elif [[ "$expanded_destination" = "$expanded_source" ]]; then
37
44
  die_with_error "Source and Destination Ruby are the same ($expanded_destination)"
45
+
38
46
  elif [[ ! -d "$rvm_rubies_path/$expanded_source" ]]; then
39
47
  die_with_error "Ruby '$expanded_source' is not installed - please install it first."
48
+
40
49
  elif [[ ! -d "$rvm_rubies_path/$expanded_destination" ]]; then
41
50
  die_with_error "Ruby '$expanded_destination' is not installed - please install it first."
42
51
  fi
43
52
 
44
53
  echo "Are you sure you wish to MOVE gems from $expanded_source to $expanded_destination?"
54
+
45
55
  confirm "This will overwrite existing gems in $expanded_destination and remove them from $expanded_source" || return 1
46
56
 
47
57
  echo "Moving gemsets..."
48
58
 
49
59
  while read -r origin_gemset; do
50
60
  [[ "$origin_gemset" = "$expanded_source" || "$origin_gemset" = "$expanded_source$rvm_gemset_separator"* ]] || continue
61
+
51
62
  gemset_name="${origin_gemset/*${rvm_gemset_separator}/}"
63
+
52
64
  destination_gemset="$expanded_destination"
65
+
53
66
  if [[ -n "$gemset_name" ]]; then
54
67
  destination_gemset="$destination_gemset$rvm_gemset_separator$gemset_name"
55
68
  fi
69
+
56
70
  echo "Moving $origin_gemset to $destination_gemset"
57
71
 
58
- \rm -rf "$rvm_gems_path/$destination_gemset"
72
+ rm -rf "$rvm_gems_path/$destination_gemset"
59
73
  result="$?"
60
- [[ "$result" -gt "0" ]] && die_with_error "Unable to remove gem directory '$rvm_gems_path/$destination_gemset'" "$result"
74
+
75
+ [[ $result -gt 0 ]] && die_with_error "Unable to remove gem directory '$rvm_gems_path/$destination_gemset'" "$result"
61
76
 
62
77
  mv "$rvm_gems_path/$origin_gemset" "$rvm_gems_path/$destination_gemset"
63
78
  result="$?"
64
- [[ "$result" -gt "0" ]] && die_with_error "Unable to move '$rvm_gems_path/$origin_gemset' to '$rvm_gems_path/$destination_gemset'" "$result"
79
+
80
+ [[ $result -gt 0 ]] && die_with_error "Unable to move '$rvm_gems_path/$origin_gemset' to '$rvm_gems_path/$destination_gemset'" "$result"
65
81
 
66
82
  echo "Making gemset $destination_gemset pristine."
83
+
67
84
  __rvm_run_with_env "gemset.pristine" "$destination_gemset" "rvm gemset pristine"
85
+
68
86
  done < <("$rvm_scripts_path/list" gemsets strings | \grep "^$expanded_source")
69
- unset origin_gemset destination_gemset gemset_name
87
+
70
88
 
71
89
  if confirm 'Do you wish to move over aliases?' ; then
90
+
72
91
  while read -r alias_pair; do
92
+
73
93
  migrate_ruby_name="${alias_pair/*=/}"
94
+
74
95
  migrate_alias_name="${alias_pair/=*/}"
96
+
75
97
  if [[ "$migrate_ruby_name" = "$expanded_source" || "$migrate_ruby_name" = "$expanded_source$rvm_gemset_separator"* ]]; then
98
+
76
99
  migrate_new_alias_name="${migrate_ruby_name/$expanded_source/$expanded_destination}"
100
+
77
101
  echo "Updating alias $migrate_alias_name to point to $migrate_new_alias_name"
102
+
78
103
  "$rvm_scripts_path/alias" delete "$migrate_alias_name" >/dev/null 2>&1
104
+
79
105
  "$rvm_scripts_path/alias" create "$migrate_alias_name" "$migrate_new_alias_name" >/dev/null 2>&1
80
106
  fi
107
+
81
108
  done < "$rvm_config_path/alias"
82
- unset migrate_ruby_name migrate_alias_name migrate_new_alias_name
109
+
83
110
  fi
84
111
 
85
112
  if confirm "Do you wish to move over wrappers?" ; then
113
+
86
114
  origin_wrappers_path="$rvm_wrappers_path/$expanded_source"
87
- for binary_name in $(\ls "$rvm_bin_path") ; do
115
+
116
+ binaries=($(cd "$rvm_bin_path" ; find * -type f -maxdepth 0))
117
+
118
+ for binary_name in "${binaries[@]}" ; do
119
+
88
120
  full_bin_path="$rvm_bin_path/$binary_name"
121
+
89
122
  [[ ! -L "$full_bin_path" ]] && continue
123
+
90
124
  expanded_symlink="$(readlink "$full_bin_path")"
125
+
91
126
  [[ "$expanded_symlink" != "$origin_wrappers_path/"* ]] && continue
127
+
92
128
  linked_binary_name="$(basename "$expanded_symlink")"
129
+
93
130
  [[ "$binary_name" = "$linked_binary_name-$expanded_source" || "$binary_name" = "$expanded_source" ]] && continue
131
+
94
132
  new_wrapper_destination="${expanded_symlink/$expanded_source/$expanded_destination}"
133
+
95
134
  ln -sf "$new_wrapper_destination" "$full_bin_path"
96
135
  done
97
- unset origin_wrappers_path full_bin_path expanded_symlink linked_binary_name new_wrapper_destination
98
136
  fi
99
137
 
100
138
  if confirm "Do you also wish to completely remove $expanded_source (inc. archive)?" ; then
139
+
101
140
  __rvm_run_with_env "rvm.remove" "$expanded_source" "rvm remove $expanded_source --archive --gems"
141
+
102
142
  fi
103
143
 
104
144
  echo "Successfully migrated $expanded_source to $expanded_destination"
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- if [[ -z "$rvm_leave_gem_alone" ]]; then
3
+ if [[ ${rvm_leave_gem_alone:-0} -eq 0 ]]; then
4
4
  gem() {
5
- command gem "$@"
6
- local gem_result="$?"
5
+ local result
6
+
7
+ command gem "$@" ; result="$?"
8
+
7
9
  hash -r
8
- return $gem_result
10
+
11
+ return $result
9
12
  }
10
- fi
13
+ fi
@@ -7,8 +7,8 @@ source "$rvm_scripts_path/base"
7
7
 
8
8
  # Tools to make managing ruby dependencies inside of rvm easier.
9
9
  args=($*)
10
- action="${args[0]}"
11
- library="${args[1]}"
10
+ action="${args[0]:-""}"
11
+ library="${args[1]:-""}"
12
12
  args="$(echo ${args[@]:2})"
13
13
 
14
14
  install_package() {
@@ -191,12 +191,15 @@ llvm() {
191
191
  )
192
192
  }
193
193
 
194
- if [[ ! -z "$library" ]] ; then
195
- if [[ " readline iconv curl openssl zlib autoconf ncurses pkgconfig gettext glib mono llvm libxml2 " =~ "$library" ]] ; then
196
- ${library}
197
- else
198
- "$rvm_scripts_path/log" "error" "Package '${library}' is unknown."
199
- fi
194
+ if [[ -n "$library" ]] ; then
195
+ case $library in
196
+ readline|iconv|curl|openssl|zlib|autoconf|ncurses|pkgconfig|gettext|glib|mono|llvm|libxml2)
197
+ ${library}
198
+ ;;
199
+ *)
200
+ "$rvm_scripts_path/log" "error" "Package '${library}' is unknown."
201
+ ;;
202
+ esac
200
203
  else
201
204
  "$rvm_scripts_path/log" "info" "Usage: 'rvm package {install,uninstall} {readline,iconv,curl,openssl,zlib,autoconf,ncurses,pkgconfig,gettext,glib,mono,llvm,libxml2}'"
202
205
  exit 1
@@ -12,27 +12,45 @@ __rvm_patch_lookup_path() {
12
12
  }
13
13
 
14
14
  __rvm_expand_patch_name() {
15
- local name="$1"
15
+ local name expanded_patch_name
16
+
17
+ name="${1:-""}"
18
+
16
19
  [[ -z "$name" ]] && return 0
20
+
17
21
  expanded_patch_name="$("$rvm_scripts_path/patchsets" show "$name")"
22
+
18
23
  if [[ "$?" == "0" ]]; then
19
24
  echo "${expanded_patch_name}"
25
+
20
26
  elif [[ "$name" != "default" ]]; then
21
27
  echo "$name"
22
- fi ; unset expanded_patch_name
28
+ fi
29
+
30
+ return 0
23
31
  }
24
32
 
25
33
  # Return the full patch for a given patch.
26
34
  __rvm_lookup_full_patch_path() {
35
+ local extension patch_path directory directories
36
+
27
37
  # Absolute path, pwd and then finally the rvm patches path.
28
- for directory in $(__rvm_patch_lookup_path) ; do
38
+ directories=($(__rvm_patch_lookup_path))
39
+
40
+ for directory in "${directories[@]}" ; do
41
+
29
42
  for extension in {"",.patch,.diff}; do
43
+
30
44
  patch_path="${directory}${1}${extension}"
45
+
31
46
  if [[ -s "$patch_path" ]]; then
32
47
  echo "$patch_path"
33
- return
48
+ return 0
34
49
  fi
35
- done; unset extension patch_path
36
- done; unset directory
50
+
51
+ done
52
+
53
+ done
54
+
37
55
  return 1
38
56
  }
@@ -15,7 +15,8 @@ repair_symlinks() {
15
15
  for executable_name in $(\find \. -type l); do
16
16
  [[ -e "$executable_name" || "$(readlink "$executable_name")" != "$rvm_wrappers_path/"* ]] && continue
17
17
  if [[ -f "$executable_name" ]] ; then
18
- "$rvm_scripts_path/log" "info" "Removing stale symlink from $(basename "$executable_name")"
18
+ "$rvm_scripts_path/log" "info" \
19
+ "Removing stale symlink from $(basename "$executable_name")"
19
20
  \rm -f "$executable_name"
20
21
  fi
21
22
  done
@@ -24,31 +25,69 @@ repair_symlinks() {
24
25
 
25
26
  # Regenerates each symlink file.
26
27
  repair_environments() {
27
- for environment_name in $(\ls "$rvm_environments_path"); do
28
+ local environment_name environments
29
+
30
+ environments=($(cd "$rvm_environments_path" ; find * -type f -maxdepth 0))
31
+
32
+ for environment_name in "${environments[@]}" ; do
33
+
28
34
  [[ -L "$rvm_environments_path/$environment_name" ]] && continue
29
- "$rvm_scripts_path/log" "info" "Regenerating environment file for '$environment_name'"
35
+
36
+ "$rvm_scripts_path/log" "info" \
37
+ "Regenerating environment file for '$environment_name'"
38
+
30
39
  [[ -f "$rvm_environments_path/$environment_name" ]] && \rm -f "$rvm_environments_path/$environment_name"
31
- (source "$rvm_scripts_path/base"; __rvm_become "$environment_name"; __rvm_ensure_has_environment_files)
32
- done; unset environment_name
40
+
41
+ (
42
+ source "$rvm_scripts_path/base"
43
+
44
+ __rvm_become "$environment_name"
45
+
46
+ __rvm_ensure_has_environment_files
47
+ )
48
+
49
+ done
33
50
  }
34
51
 
35
52
  # Removes archives that have incorrect md5 sums.
36
53
  repair_archives() {
37
- for archive_file in $(\ls "$rvm_archives_path"); do
54
+
55
+ local archive_file archives stored_md5sum
56
+
57
+ archives=($(cd "$rvm_archives_path" ; find * -type f -maxdepth 0))
58
+
59
+ for archive_file in "${archives[@]}" ; do
60
+
38
61
  [[ -f "$rvm_archives_path/$archive_file" ]] || continue
39
- local stored_md5sum="$($rvm_scripts_path/db "$rvm_config_path/md5" "$archive_file" | head -n1)"
40
- if [[ -n "$stored_md5sum" ]] && ! "$rvm_scripts_path/md5" "$rvm_archives_path/$archive_file" "$stored_md5sum" ; then
41
- "$rvm_scripts_path/log" "info" "Removing archive for '$archive_file' - Incorrect md5 checksum."
42
- \rm -rf "$rvm_archives_path/$archive_file"
62
+
63
+ stored_md5sum="$($rvm_scripts_path/db "$rvm_config_path/md5" "$archive_file" | head -n1)"
64
+
65
+ if [[ -n "$stored_md5sum" ]] ; then
66
+
67
+ if [[ ! "$rvm_scripts_path/md5" "$rvm_archives_path/$archive_file" "$stored_md5sum" ]] ; then
68
+
69
+ "$rvm_scripts_path/log" "info" "Removing archive for '$archive_file' - Incorrect md5 checksum."
70
+
71
+ rm -rf "$rvm_archives_path/$archive_file"
72
+ fi
43
73
  fi
44
- done; unset archive_file
74
+ done
75
+
76
+ return 0
45
77
  }
46
78
 
47
79
  repair_all() {
80
+
48
81
  repair_symlinks
82
+
49
83
  repair_archives
84
+
50
85
  repair_environments
51
- "$rvm_scripts_path/log" "info" "All items repaired."
86
+
87
+ "$rvm_scripts_path/log" "info" \
88
+ "symlinks, archives and environments have been repaired."
89
+
90
+ return 0
52
91
  }
53
92
 
54
93
  args=($*)
@@ -56,7 +95,8 @@ action="${args[0]}"
56
95
  args="$(echo ${args[@]:1}) " # Strip trailing / leading / extra spacing.
57
96
 
58
97
  if [[ -z "$action" ]]; then
59
- usage ; exit $?
98
+ usage
99
+ exit $?
60
100
  fi
61
101
 
62
102
  case "$action" in
@@ -63,7 +63,8 @@ if [[ $rvm_loaded_flag -eq 0 || $rvm_reload_flag -eq 1 ]] ; then
63
63
 
64
64
  rvm_loaded_flag=1
65
65
 
66
- rvm_version="$(tail -n 3 < "${rvm_path}/lib/VERSION.yml" | sed -e 's/^.*: //g' | \tr "\n" '.' | sed -e 's/\.$//')" ; export rvm_version
66
+ rvm_version="$(awk '/:/{printf $NF"."}' "$rvm_path/lib/VERSION.yml")"
67
+ export rvm_version="${rvm_version/%.}"
67
68
 
68
69
  alias rvm-restart="source '${rvm_path}/scripts/rvm'"
69
70
 
@@ -383,7 +383,8 @@ for file in rvm rvmsudo rvm-shell rvm-auto-ruby ; do
383
383
  [[ -s "$rvm_bin_path/$file" ]] && chmod +x "$rvm_bin_path/$file"
384
384
  done; unset file
385
385
  printf "\n Copying manpages into place."
386
- for man_file in $(ls "$install_source_path/man"); do
386
+
387
+ for man_file in $(builtin cd "$install_source_path/man" ; find * -type f -maxdepth 0 -print); do
387
388
  rm -rf "$rvm_man_path/$man_file"
388
389
  cp -R "$install_source_path/man/$man_file" "$rvm_man_path/"
389
390
  done
@@ -217,7 +217,7 @@ __rvm_select() {
217
217
  rvm_ruby_minor_version="${rvm_ruby_version//*.}"
218
218
  fi
219
219
 
220
- rvm_ruby_package_name="${rvm_ruby_package_name:-$(echo $rvm_ruby_string | sed -e 's/-n.*$//')}"
220
+ rvm_ruby_package_name="${rvm_ruby_package_name:-${rvm_ruby_string//-n*}}"
221
221
  rvm_ruby_home="$rvm_rubies_path/$rvm_ruby_string"
222
222
  rvm_ruby_log_path="$rvm_log_path/$rvm_ruby_string"
223
223
  rvm_ruby_repo_path="$rvm_repo_path/$rvm_ruby_string"
@@ -241,24 +241,19 @@ __rvm_select() {
241
241
 
242
242
  \mkdir -p "$rvm_ruby_log_path"
243
243
 
244
- export rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_url rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_configure_flags rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_ruby_release_version rvm_ruby_major_version rvm_ruby_minor_version rvm_gemset_name rvm_gems_path rvm_ruby_gem_home rvm_path rvm_src_path rvm_bin_path rvm_ruby_binary rvm_ruby_home rvm_log_path rvm_ruby_log_path rvm_src_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string
244
+ export rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_url rvm_ruby_patch_level rvm_ruby_configure rvm_configure_flags rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_ruby_release_version rvm_ruby_major_version rvm_ruby_minor_version rvm_gemset_name rvm_gems_path rvm_ruby_gem_home rvm_path rvm_src_path rvm_bin_path rvm_ruby_binary rvm_ruby_home rvm_log_path rvm_ruby_log_path rvm_src_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string
245
245
  else
246
246
  rvm_ruby_interpreter="${rvm_ruby_interpreter:-system}"
247
247
  fi
248
248
  }
249
249
 
250
250
  __rvm_use() {
251
- rvm_head_flag=${rvm_head_flag:-0}
252
- rvm_default_flag=${rvm_default_flag:-0}
253
- rvm_rvmrc_flag=${rvm_rvmrc_flag:-0}
254
- rvm_verbose_flag=${rvm_verbose_flag:-0}
255
- rvm_sticky_flag=${rvm_sticky_flag:-0}
256
251
  rvm_gemset_name="${rvm_gemset_name:-""}"
257
252
  rvm_ruby_gem_home="${rvm_ruby_gem_home:-""}"
258
253
  rvm_wrapper_name="${rvm_wrapper_name:-""}"
259
254
  rvm_ruby_alias="${rvm_ruby_alias:-""}"
260
255
 
261
- local new_path=""
256
+ local new_path binary full_binary_path
262
257
 
263
258
  if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select "$@" ; fi
264
259
 
@@ -282,7 +277,6 @@ __rvm_use() {
282
277
  fi
283
278
 
284
279
  # Check binaries, remove under the condition they're symlinks.
285
- local binary full_binary_path
286
280
  if [[ "$rvm_selfcontained" = "0" ]] ; then
287
281
 
288
282
  for binary in ruby gem irb ri rdoc rake erb testrb ; do
@@ -311,7 +305,7 @@ __rvm_use() {
311
305
 
312
306
  if [[ ! -d "$MY_RUBY_HOME" ]] ; then
313
307
  "$rvm_scripts_path/log" "warn" "$rvm_ruby_interpreter $rvm_ruby_string is not installed."
314
- if [[ $rvm_install_on_use_flag -eq 1 ]] ; then
308
+ if [[ ${rvm_install_on_use_flag:-0} -eq 1 ]] ; then
315
309
  "$rvm_scripts_path/manage" "install" "$rvm_ruby_string"
316
310
  else
317
311
  "$rvm_scripts_path/log" "info" "To install do: 'rvm install $rvm_ruby_string'"
@@ -323,14 +317,17 @@ __rvm_use() {
323
317
  __rvm_ensure_has_environment_files
324
318
 
325
319
  [[ ${rvm_verbose_flag:-0} -gt 0 ]] && \
326
- "$rvm_scripts_path/log" "info" "Using $(basename $GEM_HOME | \tr '-' ' ' | sed 's/'${rvm_gemset_separator}'/ with gemset /')"
320
+ "$rvm_scripts_path/log" "info" \
321
+ "Using ${GEM_HOME/${rvm_gemset_separator:-'@'}/ with gemset }"
327
322
 
328
323
  new_path="$GEM_HOME/bin:$rvm_ruby_global_gems_path/bin:$MY_RUBY_HOME/bin:$rvm_bin_path:$(__rvm_remove_rvm_from_path ; printf "$PATH")"
329
324
  fi
330
325
 
331
326
  # Export ruby string and gem set me for extrenal scripts to take advantage of them.
332
327
  if [[ -n "${rvm_ruby_string:-""}" ]] ; then export rvm_ruby_string ; fi
328
+
333
329
  if [[ -n "${rvm_gemset_name:-""}" ]] ; then export rvm_gemset_name ; fi
330
+
334
331
  if [[ -n "$new_path" ]]; then
335
332
  export PATH="$new_path"
336
333
  unset new_path
@@ -342,18 +339,21 @@ __rvm_use() {
342
339
  local environment_id="$(__rvm_environment_identifier)"
343
340
 
344
341
  if [[ ${rvm_default_flag:-0} -eq 1 && "default" != "${rvm_ruby_interpreter:-""}" ]] ; then
342
+
345
343
  if [[ "${rvm_selfcontained:-""}" = "0" ]] ; then
346
344
  # Sets up the default wrappers.
347
345
  "$rvm_scripts_path/wrapper" "$rvm_ruby_string" --no-prefix
348
346
  else
349
347
  "$rvm_scripts_path/wrapper" "$rvm_scripts_path" "default"
350
348
  fi
349
+
351
350
  if [[ "system" = "$rvm_ruby_interpreter" ]] ; then
352
351
  "$rvm_scripts_path/alias" delete default &> /dev/null
353
- \find "$rvm_bin_path" -name 'default_*' -maxdepth 1 -delete
352
+ \find "$rvm_bin_path" -name 'default_*' -maxdepth 0 -delete
354
353
  \rm -f "$rvm_config_path/default"
355
354
  \rm -f "$rvm_environments_path/default"
356
355
  \rm -rf "$rvm_wrappers_path/default"
356
+
357
357
  else
358
358
  RUBY_VERSION="$("$rvm_ruby_home/bin/ruby" -v | sed 's#^\(.*\) (.*$#\1#')"
359
359
  export GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION
@@ -432,103 +432,131 @@ __rvm_ruby_string() {
432
432
 
433
433
  __rvm_unset_ruby_variables
434
434
 
435
- for string in $(printf "${ruby_string//-/ }") ; do
435
+ strings=(${ruby_string//-/ })
436
+
437
+ for string in "${strings[@]}" ; do
438
+
439
+ # TODO: case...
440
+
441
+ case "$string" in
442
+ head)
436
443
 
437
- if [[ "head" = "$string" ]] ; then
438
444
  rvm_ruby_revision="head"
439
445
  rvm_ruby_patch_level="" ; rvm_ruby_revision="" ; rvm_ruby_tag=""
440
446
  export rvm_head_flag=1
447
+ ;;
441
448
 
442
- elif [[ "system" = "$string" ]] ; then
449
+ system)
443
450
  rvm_ruby_interpreter="system"
444
451
  rvm_ruby_patch_level="" ; rvm_ruby_tag="" ; rvm_head_flag=0 ; rvm_ruby_revision="" ; rvm_ruby_version="" ; rvm_gemset_name=""
445
452
  return 0
453
+ ;;
446
454
 
447
- elif [[ "nightly" = "$string" ]] ; then
455
+ nightly)
448
456
  rvm_ruby_version="nightly"
449
457
  rvm_nightly_flag=1
450
458
  break
459
+ ;;
451
460
 
452
- elif "$rvm_scripts_path/match" "$string" "^preview" ; then
461
+ preview*)
453
462
  rvm_ruby_patch_level="$string"
463
+ ;;
454
464
 
455
- elif "$rvm_scripts_path/match" "$string" "^rc[0-9]" ; then
465
+ rc[[:digit:]]*)
456
466
  rvm_ruby_patch_level="$string"
467
+ ;;
457
468
 
458
- elif "$rvm_scripts_path/match" "$string" "^[0-9]\.[0-9]" ; then
469
+ [[:digit:]]\.[[:digit:]]*)
459
470
  rvm_ruby_version="$string"
460
- rvm_ruby_revision="" ; rvm_ruby_tag=""
471
+ rvm_ruby_revision=""
472
+ rvm_ruby_tag=""
473
+ ;;
461
474
 
462
- elif "$rvm_scripts_path/match" "$string" "^p[0-9]" ; then
475
+ p[[:digit:]]*)
463
476
  rvm_ruby_patch_level="$string"
464
-
465
- elif [[ -n "${rvm_ruby_version:-""}" ]] && "$rvm_scripts_path/match" "$string" "^[0-9][0-9]" ; then
466
- if [[ "ree" = "${rvm_ruby_interpreter:-""}" ]] ; then
467
- rvm_ruby_patch_level="$string"
468
- rvm_ruby_revision=""
469
-
470
- elif [[ "rbx" = "${rvm_ruby_interpreter:-""}" ]] ; then
471
- rvm_ruby_patch_level="$string"
472
-
473
- elif [[ "maglev" = "${rvm_ruby_interpreter:-""}" ]] ; then
474
- rvm_ruby_version="$string" ; rvm_ruby_revision="" ; rvm_ruby_patch_level=""
475
-
476
- else
477
- rvm_ruby_revision="r$string"
478
- fi
479
-
480
- elif "$rvm_scripts_path/match" "$string" "^r[0-9]" ; then
477
+ ;;
478
+
479
+ #elif [[ -n "${rvm_ruby_version:-""}" ]] && "$rvm_scripts_path/match" "$string" "^
480
+ [[:digit:]][[:digit:]]*)
481
+
482
+ case "${rvm_ruby_interpreter:-""}" in
483
+ ree)
484
+ rvm_ruby_patch_level="$string"
485
+ rvm_ruby_revision=""
486
+ ;;
487
+
488
+ rbx)
489
+ rvm_ruby_patch_level="$string"
490
+ ;;
491
+
492
+ maglev)
493
+ rvm_ruby_version="$string"
494
+ rvm_ruby_revision=""
495
+ rvm_ruby_patch_level=""
496
+ ;;
497
+
498
+ *)
499
+ rvm_ruby_revision="r$string"
500
+ ;;
501
+ esac
502
+ ;;
503
+
504
+ r[[:digit:]]*)
481
505
  rvm_ruby_patch_level=""
482
506
  rvm_ruby_revision="$string"
507
+ ;;
483
508
 
484
- elif "$rvm_scripts_path/match" "$string" "^s[0-9]" ; then
509
+ s[[:digit:]]*)
485
510
  rvm_ruby_revision=""
486
511
  rvm_ruby_sha="$string"
512
+ ;;
487
513
 
488
- elif "$rvm_scripts_path/match" "$string" "^t[v0-9]" ; then
514
+ tv[[:digit:]]* | t[[:digit:]]*)
489
515
  rvm_ruby_patch_level="" ; rvm_ruby_revision=""
490
516
  rvm_ruby_tag="$string"
517
+ ;;
491
518
 
492
- elif "$rvm_scripts_path/match" "$string" "^m[0-9]" ; then
519
+ m[[:digit:]]*)
493
520
  rvm_ruby_mode="$string"
521
+ ;;
494
522
 
495
- elif "$rvm_scripts_path/match" "$string" "^u[a-z0-9]" ; then
523
+ u[[:alnum:]]*)
496
524
  rvm_ruby_patch_level="" ; rvm_ruby_revision="" ; rvm_ruby_tag="" ; rvm_ruby_patch=""
497
525
  rvm_ruby_user_tag="$string"
526
+ ;;
498
527
 
499
- elif "$rvm_scripts_path/match" "$string" "^b[0-9][0-9]" ; then
528
+ b[[:digit:]][[:digit:]]*)
500
529
  rvm_ruby_bits="$string"
530
+ ;;
501
531
 
502
- elif "$rvm_scripts_path/match" "$string" "^n" ; then
532
+ n*)
503
533
  rvm_ruby_name="${string/n/}"
534
+ ;;
504
535
 
505
- elif [[ "ruby rbx jruby macruby ree rubinius maglev mput shyouhei ironruby " =~ "$string " ]] ; then
506
- # NOTE: The space at the end of each of the above strings is *very* important.
536
+ ruby|rbx|jruby|macruby|ree|rubinius|maglev|mput|shyouhei|ironruby)
507
537
  rvm_ruby_interpreter="$string"
538
+ ;;
508
539
 
509
- else
510
- "$rvm_scripts_path/log" "error" "Unknown ruby string component: '$string'"
540
+ *)
541
+ "$rvm_scripts_path/log" "error" \
542
+ "Unknown ruby string component: '$string'"
511
543
  return 1
512
- fi
544
+ ;;
545
+ esac
513
546
  done
514
547
 
515
- # Unspecified interpreter
516
548
  if [[ -z "${rvm_ruby_interpreter:-""}" ]] ; then
517
-
518
- if "$rvm_scripts_path/match" "$rvm_ruby_version" "^1\.[8-9]" ; then
519
- rvm_ruby_interpreter="ruby"
520
-
521
- elif "$rvm_scripts_path/match" "$rvm_ruby_version" "^0.5" ; then
522
- rvm_ruby_interpreter="macruby"
523
-
524
- elif "$rvm_scripts_path/match" "$rvm_ruby_version" "^1.[2-4]" ; then
525
- rvm_ruby_interpreter="jruby"
526
- fi
549
+ # Detect interpreter based on version.
550
+ case "$rvm_ruby_version" in
551
+ 1.[8-9]*) rvm_ruby_interpreter="ruby" ;;
552
+ 0.[5-6]*) rvm_ruby_interpreter="macruby" ;;
553
+ 1.[2-7]*) rvm_ruby_interpreter="jruby" ;;
554
+ esac
527
555
  fi
528
556
 
529
557
  # Unspecified version
530
558
  rvm_ruby_version=${rvm_ruby_version:-""}
531
- if [[ -z "${rvm_ruby_version:-""}" || ${rvm_head_flag:-0} -eq 0 ]] ; then
559
+ if [[ -z "${rvm_ruby_version:-""}" && ${rvm_head_flag:-0} -eq 0 ]] ; then
532
560
  rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "${rvm_ruby_interpreter}_version")"}
533
561
  fi
534
562
 
@@ -568,15 +596,15 @@ __rvm_ruby_string() {
568
596
 
569
597
  if [[ -n "${rvm_ruby_patch_level:-""}" ]] ; then
570
598
 
571
- rvm_ruby_patch_level="$(echo $rvm_ruby_patch_level | sed 's#^pp#p#')"
599
+ rvm_ruby_patch_level="${rvm_ruby_patch_level/#pp/p}"
572
600
  rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_patch_level}"
573
601
 
574
- if [[ "ree" = "${rvm_ruby_interpreter:-""}" ]] || [[ "rbx" = "${rvm_ruby_interpreter:-""}" ]] ; then
575
- rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-p*#-#')"
602
+ if [[ "ree" = "${rvm_ruby_interpreter:-""}" || "rbx" = "${rvm_ruby_interpreter:-""}" ]] ; then
603
+ rvm_ruby_string="${rvm_ruby_string//-p*/-}"
576
604
 
577
605
  else
578
- rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-pp#-p#')"
579
- rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-prc#-rc#')"
606
+ rvm_ruby_string="${rvm_ruby_string//-pp/-p}"
607
+ rvm_ruby_string="${rvm_ruby_string//-prc/-rc}"
580
608
  fi
581
609
  fi
582
610
  fi
@@ -589,13 +617,13 @@ __rvm_ruby_string() {
589
617
  # Select a gemset based on CLI set options and environment.
590
618
  # This only sets 'rvm_ruby_gem_home'
591
619
  __rvm_gemset_select() {
620
+
592
621
  command -v gem > /dev/null
593
622
  if [[ $? -gt 0 ]] ; then return 0 ; fi # Stop if no 'gem' command is available.
594
623
 
595
624
  rvm_ruby_gem_home=${rvm_ruby_gem_home:-""}
596
625
  rvm_gemset_name=${rvm_gemset_name:-""}
597
-
598
- rvm_ruby_global_gems_path="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}global"
626
+ rvm_ruby_global_gems_path="$rvm_path/gems/${rvm_ruby_string:-""}${rvm_gemset_separator}global"
599
627
 
600
628
  if [[ -z "${rvm_gemset_name:-""}" ]] ; then
601
629
 
@@ -612,14 +640,15 @@ __rvm_gemset_select() {
612
640
  fi
613
641
  fi
614
642
 
615
- if [[ -n "${rvm_gemset_name:-""}" ]] && ! "$rvm_scripts_path/match" "$rvm_gemset_name" "^[0-9]\.[0-9]" ; then
643
+ if ! echo "${rvm_gemset_name:-""}" | grep -q "^[[:digit:]]\.[[:digit:]]" ; then
644
+
616
645
  rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}"
617
646
 
618
647
  else
619
- if [[ -n "${rvm_ruby_string:-""}" ]] && [[ "${rvm_ruby_interpreter:-""}" != "system" ]] ; then
648
+ if [[ -n "${rvm_ruby_string:-""}" && "${rvm_ruby_interpreter:-""}" != "system" ]] ; then
620
649
  rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string"
621
650
 
622
- elif [[ -z "${GEM_HOME:-""}" ]] && [[ -n "$(command -v gem)" ]] ; then
651
+ elif [[ -z "${GEM_HOME:-""}" && -n "$(command -v gem)" ]] ; then
623
652
  rvm_ruby_gem_home=$(gem env gemdir)
624
653
 
625
654
  elif [[ -n "${GEM_HOME:-""}" ]] ; then
@@ -654,10 +683,14 @@ __rvm_gemset_select() {
654
683
 
655
684
  # If the gemset does not exist, then notify the user as such and abort the action.
656
685
  if [[ -n "${rvm_gemset_name:-""}" && ! -d "$rvm_ruby_gem_home" ]] ; then
686
+
657
687
  if [[ ${rvm_gemset_create_on_use_flag:-0} -ne 1 && ${rvm_create_flag:-0} -ne 1 && ${rvm_delete_flag:-0} -ne 1 ]] ; then
688
+
658
689
  "$rvm_scripts_path/log" "error" "Gemset '$rvm_gemset_name' does not exist, rvm gemset create '$rvm_gemset_name' first."
690
+
659
691
  return 1
660
692
  fi
693
+
661
694
  elif [[ ${rvm_delete_flag:-0} -eq 1 ]] ; then
662
695
  return 1
663
696
  fi
@@ -705,7 +738,7 @@ __rvm_gemset_use() {
705
738
  "$rvm_scripts_path/log" "info" "Now using gemset '${rvm_gemset_name:-default}'"
706
739
  fi
707
740
 
708
- rvm_ruby_gem_home="$(echo "${GEM_HOME:-""}" | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}${rvm_gemset_name}"
741
+ rvm_ruby_gem_home="${GEM_HOME//${rvm_gemset_separator}*}${rvm_gemset_separator}${rvm_gemset_name}"
709
742
  GEM_HOME="$rvm_ruby_gem_home"
710
743
  BUNDLE_PATH="$rvm_ruby_gem_home"
711
744
  GEM_PATH="$rvm_ruby_gem_home/bin:$(echo "$GEM_HOME" | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global/bin"
@@ -719,7 +752,7 @@ __rvm_gemset_use() {
719
752
 
720
753
  __rvm_gemset_clear() {
721
754
  rvm_gemset_name="" ; shift # TODO: Is this shift necessary???
722
- rvm_ruby_gem_home="$(echo "${GEM_HOME:-""}" | sed "s#${rvm_gemset_separator:-'@'}.*\$##g")"
755
+ rvm_ruby_gem_home="${GEM_HOME//${rvm_gemset_separator:-'@'}*}"
723
756
  rvm_ruby_global_gems_path="$(echo "${GEM_HOME:-""}" | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global"
724
757
  GEM_HOME=$rvm_ruby_gem_home
725
758
  BUNDLE_PATH="$rvm_ruby_gem_home"