-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
selector
executable file
·952 lines (815 loc) · 29.1 KB
/
selector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
#!/usr/bin/env bash
# __rvm_select implementation version patch_level
__rvm_select()
{
true ${rvm_gemset_name:=}
typeset _original_env_string
_original_env_string=${rvm_env_string}
# Set Variable Defaults
export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC
export rvm_env_string rvm_action rvm_alias_expanded rvm_archive_extension rvm_bin_flag rvm_bin_path rvm_configure_flags rvm_debug_flag rvm_default_flag rvm_delete_flag rvm_docs_type rvm_dump_environment_flag rvm_error_message rvm_expanding_aliases rvm_file_name rvm_gemdir_flag rvm_gemset_name rvm_gemstone_package_file rvm_gemstone_url rvm_head_flag rvm_hook rvm_install_args rvm_install_on_use_flag rvm_llvm_flag rvm_loaded_flag rvm_make_flags rvm_niceness rvm_nightly_flag rvm_only_path_flag rvm_parse_break rvm_patch_names rvm_patch_original_pwd rvm_pretty_print_flag rvm_proxy rvm_quiet_flag rvm_ree_options rvm_reload_flag rvm_remove_flag rvm_ruby_alias rvm_ruby_aliases rvm_ruby_args rvm_ruby_binary rvm_ruby_bits rvm_ruby_configure rvm_ruby_file rvm_ruby_gem_home rvm_ruby_gem_path rvm_ruby_global_gems_path rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_load_path rvm_ruby_major_version rvm_ruby_make rvm_ruby_make_install rvm_ruby_minor_version rvm_ruby_mode rvm_ruby_name rvm_ruby_package_file rvm_ruby_package_name rvm_ruby_patch rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_require rvm_ruby_revision rvm_ruby_selected_flag rvm_ruby_sha rvm_ruby_string rvm_ruby_strings rvm_ruby_tag rvm_ruby_url rvm_ruby_user_tag rvm_ruby_version rvm_script_name rvm_sdk rvm_silent_flag rvm_sticky_flag rvm_system_flag rvm_token rvm_trace_flag rvm_use_flag rvm_user_flag rvm_verbose_flag rvm_wrapper_name rvm_architectures
if [[ -z "${rvm_ruby_string:-}" ]]
then # First we build rvm_ruby_string from components if it is empty.
if [[ -n "${rvm_ruby_interpreter:-}" ]]
then
rvm_ruby_string="$rvm_ruby_interpreter"
fi
if [[ -n "${rvm_ruby_version:-}" ]]
then
rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_version"
fi
if [[ -n "${rvm_ruby_patch_level:-}" ]]
then
rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_patch_level"
fi
if [[ -n "${rvm_ruby_revision:-}" ]]
then
rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_revision"
fi
if [[ -n "${rvm_ruby_name:-}" ]]
then
rvm_ruby_name="$rvm_ruby_string-$rvm_ruby_name"
fi
fi
__rvm_ruby_string || return $?
rvm_archive_extension="tar.gz"
if [[ -z "${rvm_ruby_interpreter:-}" ]]
then
rvm_ruby_interpreter="${rvm_ruby_string//-*/}"
fi
case "$rvm_ruby_interpreter" in
macruby)
if [[ "Darwin" == "$(uname)" ]]
then
rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
if (( ${rvm_head_flag:=0} == 1 ))
then
rvm_ruby_version="" ; rvm_ruby_tag=""
rvm_ruby_revision="head"
__rvm_db "macruby_repo_url" "rvm_ruby_repo_url"
rvm_ruby_url="$rvm_ruby_repo_url"
elif [[ "nightly" == "${rvm_ruby_version:-}" ]]
then
__rvm_db "macruby_nightly_url" "rvm_ruby_url"
rvm_ruby_package_name="${rvm_ruby_interpreter}_nightly-${rvm_ruby_version}"
rvm_ruby_package_file="$rvm_ruby_package_name"
elif [[ -n "${rvm_ruby_version:-}" ]]
then
__rvm_db "macruby_url" "rvm_ruby_url"
rvm_ruby_package_name="MacRuby%20${rvm_ruby_version}.zip"
rvm_ruby_package_file="$rvm_ruby_package_name"
rvm_ruby_url="$rvm_ruby_url/$rvm_ruby_package_name"
else
__rvm_db "macruby_version" "rvm_ruby_version"
__rvm_db "macruby_url" "rvm_ruby_url"
rvm_ruby_package_name="MacRuby%20${rvm_ruby_version}.zip"
rvm_ruby_package_file="$rvm_ruby_package_name"
rvm_ruby_url="$rvm_ruby_url/$rvm_ruby_package_name"
fi
rvm_ruby_patch_level=""
else
rvm_error "MacRuby can only be installed on a Darwin OS."
fi
;;
rbx|rubinius)
rvm_archive_extension="tar.gz"
rvm_ruby_interpreter="rbx"
rvm_ruby_version=${rvm_ruby_version:-$(__rvm_db "rbx_version")}
rvm_ruby_repo_url=${rvm_rbx_repo_url:-$(__rvm_db "rubinius_repo_url")}
rbx_url=${rbx_url:-$(__rvm_db "rbx_url")}
rvm_ruby_patch_level=""
case "${rvm_ruby_version}" in
(2.0pre)
rvm_ruby_repo_branch="master" ;;
(2.0.testing)
rvm_ruby_repo_branch="${rvm_ruby_version}" ;;
esac
if (( ${rvm_head_flag:=0} == 0 ))
then
rvm_ruby_url="${rbx_url}"
rvm_ruby_package_file="rubinius-${rvm_ruby_version}.${rvm_archive_extension}"
rvm_ruby_url="$rvm_ruby_url/$rvm_ruby_package_file"
else
rvm_ruby_version="head"
fi
if [[ -n "${rvm_rbx_opt:-}" ]]
then
export RBXOPT="${RBXOPT:=${rvm_rbx_opt}}"
fi
;;
jruby)
rvm_ruby_patch_level=""
if (( ${rvm_head_flag:=0} == 1 ))
then
rvm_ruby_version="head"
rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}"
rvm_ruby_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}"
elif [[ ${rvm_18_flag:-0} == 1 || ${rvm_19_flag:-0} == 1 ]]
then
rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}"
rvm_ruby_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}"
rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "jruby_version")"}"
rvm_ruby_tag="${rvm_ruby_tag:-${rvm_ruby_version}}"
else
rvm_archive_extension="tar.gz"
rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "jruby_version")"}"
jruby_url="$(__rvm_db "jruby_url")"
rvm_ruby_package_file="${rvm_ruby_interpreter}-bin-${rvm_ruby_version}"
rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
rvm_ruby_url="${jruby_url}/${rvm_ruby_version}/${rvm_ruby_package_file}.tar.gz"
jruby_url=""
fi
alias jruby_ng="jruby --ng"
alias jruby_ng_server="jruby --ng-server"
;;
maglev)
rvm_ruby_patch_level=""
maglev_url="$(__rvm_db "maglev_url")"
system="$(uname -s)"
if [[ "$MACHTYPE" == x86_64-apple-darwin* ]]
then
arch="i386" # Anyone else hear circus musik? ;)
else
arch="$(uname -m)"
fi
if (( ${rvm_head_flag:=0} == 1 )) || [[ "$rvm_ruby_version" == "head" ]]
then
rvm_head_flag=1
rvm_ruby_version="head"
rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "maglev_repo_url")}"
rvm_ruby_url="${rvm_ruby_repo_url:-$(__rvm_db "maglev_repo_url")}"
rvm_gemstone_version=$(
command curl -s https://raw.github.com/MagLev/maglev/master/version.txt |
GREP_OPTIONS="" \grep ^GEMSTONE | cut -f2 -d-
)
rvm_gemstone_package_file="GemStone-${rvm_gemstone_version}.${system}-${arch}"
else
rvm_ruby_package_file="MagLev-${rvm_ruby_version}" # removed from 1.0: .${system}-${arch}
rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "maglev_version")"}"
rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
rvm_ruby_url="${rvm_ruby_url:-"$maglev_url/${rvm_ruby_package_file}.${rvm_archive_extension}"}"
rvm_gemstone_version=$(
version_tag_commit=$(
command curl -s http://github.com/api/v2/yaml/repos/show/MagLev/maglev/tags |
awk '/MagLev-'${rvm_ruby_version}':/ {print $2 }'
)
command curl -s https://raw.github.com/MagLev/maglev/$version_tag_commit/version.txt |
GREP_OPTIONS="" \grep ^GEMSTONE | cut -f2 -d-
)
rvm_gemstone_package_file="GemStone-${rvm_gemstone_version}.${system}-${arch}"
export MAGLEV_HOME="$rvm_rubies_path/$rvm_ruby_string"
fi
rvm_gemstone_url="$maglev_url/${rvm_gemstone_package_file}.${rvm_archive_extension}"
;;
ironruby)
rvm_ruby_patch_level=""
if (( ${rvm_head_flag:=0} == 1 ))
then
rvm_ruby_version="head"
rvm_ruby_package_name="${rvm_ruby_string}"
rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "ironruby_repo_url")}"
rvm_ruby_url="${rvm_ruby_repo_url:-$(__rvm_db "ironruby_repo_url")}"
else
rvm_archive_extension="zip"
rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "ironruby_version")"}
rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
rvm_ruby_package_file="${rvm_ruby_interpreter}-${rvm_ruby_version}.${rvm_archive_extension}"
rvm_ruby_url="$(__rvm_db "ironruby_${rvm_ruby_version}_url")${rvm_ruby_package_file}"
fi
export rvm_ruby_version rvm_ruby_string rvm_ruby_package_name rvm_ruby_repo_url rvm_ruby_url rvm_archive_extension
;;
ree)
rvm_ruby_interpreter=ree
rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "ree_version")"}
case "$rvm_ruby_version" in
1.8.*) true ;; # all good!
*) rvm_error "Unknown Ruby Enterprise Edition version: $rvm_ruby_version" ;;
esac
if [[ -n "${rvm_ruby_patch_level:-0}" ]]
then
rvm_ruby_patch_level="$(echo $rvm_ruby_patch_level | \sed 's#^p##')"
fi
rvm_ruby_package_file="ruby-enterprise-$rvm_ruby_version-$rvm_ruby_patch_level"
rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_${rvm_ruby_patch_level}_url")"
rvm_ruby_url="${rvm_ruby_url:-$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_url")}"
rvm_ruby_url="${rvm_ruby_url}/$rvm_ruby_package_file.tar.gz"
;;
kiji)
rvm_ruby_interpreter="kiji"
rvm_ruby_version="head"
rvm_head_flag=1
rvm_ruby_string="kiji-head"
rvm_ruby_patch_level=""
rvm_ruby_repo_url=${rvm_mput_repo_url:-"$(__rvm_db "kiji_repo_url")"}
rvm_ruby_url=$rvm_ruby_repo_url
rvm_ruby_configure="" ; rvm_ruby_make="" ; rvm_ruby_make_install=""
;;
goruby)
rvm_ruby_interpreter="goruby"
rvm_ruby_version="head"
rvm_ruby_string="goruby"
rvm_ruby_patch_level=""
rvm_ruby_repo_url=${rvm_mput_repo_url:-"$(__rvm_db "goruby_repo_url")"}
rvm_ruby_url=$rvm_ruby_repo_url
rvm_ruby_configure="" ; rvm_ruby_make="" ; rvm_ruby_make_install=""
;;
tcs)
rvm_ruby_interpreter="tcs"
rvm_ruby_version="head"
rvm_ruby_string="tcs"
rvm_ruby_patch_level=""
rvm_ruby_repo_url=${rvm_tcs_repo_url:-"$(__rvm_db "tcs_repo_url")"}
rvm_ruby_url=$rvm_ruby_repo_url
rvm_ruby_repo_branch="${rvm_ruby_repo_branch:-"$(__rvm_db "tcs_repo_branch")"}"
export rvm_head_flag=1
rvm_ruby_configure="" ; rvm_ruby_make="" ; rvm_ruby_make_install=""
;;
ruby)
if [[ -n "${rvm_ruby_patch_level}" ]]
then
rvm_ruby_package_file="${rvm_ruby_interpreter}-${rvm_ruby_version}-${rvm_ruby_patch_level}"
rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}-${rvm_ruby_patch_level}"
else
rvm_ruby_package_file="${rvm_ruby_interpreter}-${rvm_ruby_version}"
rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}"
fi
if [[ -z "${rvm_ruby_version:-""}" ]] && (( ${rvm_head_flag:=0} == 0 ))
then
rvm_error "Ruby version was not specified!"
else
rvm_ruby_repo_url="${rvm_ruby_repo_url:-"$(__rvm_db "ruby_repo_url")"}"
if (( ${rvm_head_flag:=0} == 0 ))
then
case "${rvm_ruby_version}" in
(1.8.4)
rvm_archive_extension="tar.gz"
;;
(*)
rvm_archive_extension="tar.bz2"
;;
esac
fi
fi
;;
ext)
if [[ -z "${rvm_ruby_name:-${detected_rvm_ruby_name:-}}" ]]
then
rvm_error "External ruby name was not specified!"
fi
;;
current)
ruby_binary="$(builtin command -v ruby)"
if (( $? == 0)) && match "$ruby_binary" "*rvm*"
then
rvm_ruby_string="$(dirname "$ruby_binary" | xargs dirname | xargs basename)"
else
rvm_ruby_interpreter="system"
fi
;;
default|system|user)
# no-op?
;;
*)
if [[ -n "${MY_RUBY_HOME:-""}" ]]
then
rvm_ruby_string=$(basename $MY_RUBY_HOME)
__rvm_select
else
if [[ -z "${rvm_ruby_string:-""}" ]]
then
rvm_error "Ruby implementation '$rvm_ruby_interpreter' is not known."
return 1
fi
fi
esac
if [[ -n "$rvm_ruby_version" ]]
then
case "$rvm_ruby_version" in
(+([[:digit:]]).+([[:digit:]]).+([[:digit:]]))
rvm_ruby_release_version="${rvm_ruby_version/.*/}"
rvm_ruby_major_version=${rvm_ruby_version%.*} ; rvm_ruby_major_version=${rvm_ruby_major_version#*.}
rvm_ruby_minor_version="${rvm_ruby_version//*.}"
;;
(+([[:digit:]]).+([[:digit:]]))
rvm_ruby_release_version="${rvm_ruby_version/.*/}"
rvm_ruby_major_version="${rvm_ruby_version#*.}"
rvm_ruby_minor_version=""
;;
esac
fi
if [[ "${rvm_ruby_interpreter}" == ext ]]
then
rvm_ruby_home="$rvm_externals_path/$rvm_ruby_string"
rvm_ruby_irbrc="$rvm_ruby_home/.irbrc"
rvm_ruby_binary="$( readlink $rvm_ruby_home/bin/ruby )"
else
rvm_ruby_package_name="${rvm_ruby_package_name:-${rvm_ruby_string//-n*}}"
rvm_ruby_home="$rvm_rubies_path/$rvm_ruby_string"
rvm_ruby_irbrc="$rvm_ruby_home/.irbrc"
rvm_ruby_binary="$rvm_ruby_home/bin/ruby"
fi
# TODO is this right place to do this ?
if [[ "maglev" == "$rvm_ruby_interpreter" ]]
then
export MAGLEV_HOME="$rvm_ruby_home"
export GEMSTONE_GLOBAL_DIR=$MAGLEV_HOME
fi
__rvm_gemset_select
case $? in
1|3|4)
return 1
;;
esac
rvm_ruby_selected_flag=1
if [[ -d "${rvm_log_path}/$rvm_ruby_string" ]]
then
\mkdir -p "${rvm_log_path}/$rvm_ruby_string"
fi
rvm_ruby_interpreter="${rvm_ruby_interpreter:-system}"
}
__rvm_use_system() {
unset GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC
new_path="$(__rvm_remove_rvm_from_path ; printf "%b" "$PATH"):${rvm_bin_path}"
if [[ -s "$rvm_path/config/system" ]]
then
GREP_OPTIONS="" \grep "MY_RUBY_HOME='$rvm_rubies_path" "$rvm_path/config/system" > /dev/null
if (( $? == 0 ))
then
# 'system' should *not* point to an rvm ruby.
if [[ -f "$rvm_path/config/system" ]]
then
\rm -f "$rvm_path/config/system"
fi
else
source "$rvm_path/config/system"
fi
fi
if (( ${rvm_default_flag:=0} == 1 ))
then
"$rvm_scripts_path/alias" delete default &> /dev/null
\find "${rvm_bin_path}" -maxdepth 0 -name 'default_*' -delete
\rm -f "$rvm_path/config/default"
\rm -f "$rvm_environments_path/default"
__rvm_rm_rf "$rvm_wrappers_path/default"
fi
# Check binaries, remove under the condition they're symlinks.
if (( ${rvm_user_install_flag:=0} == 0 ))
then
for binary in ruby gem irb ri rdoc rake erb testrb
do
full_binary_path="${rvm_bin_path}/$binary"
if [[ -L "$full_binary_path" ]]
then
\rm -f "$full_binary_path"
fi
done
fi
if (( ${rvm_verbose_flag:=0} == 1 ))
then
rvm_log "Now using system ruby."
fi
__rvm_remove_rvm_from_path
new_path="$PATH:${rvm_bin_path}"
export rvm_ruby_string="system"
}
__rvm_use()
{
typeset new_path binary full_binary_path rvm_ruby_gem_home
__rvm_select "$@" || return $?
if [[ "system" == ${rvm_ruby_interpreter:="system"} ]]
then
__rvm_use_system
else
if [[ ! -d "$rvm_ruby_home" ]]
then
if [[ ${rvm_install_on_use_flag:-0} -eq 1 ]]
then
rvm_warn "$rvm_ruby_string is not installed."
"$rvm_scripts_path/manage" "install" "$rvm_ruby_string"
else
rvm_error "$rvm_ruby_string is not installed."
rvm_log "To install do: 'rvm install $rvm_ruby_string'"
return 1
fi
fi
if [[ ! -d "$rvm_ruby_gem_home" || -n "${rvm_expected_gemset_name}" ]]
then
if (( ${rvm_gemset_create_on_use_flag:=0} == 1 || ${rvm_create_flag:=0} == 1 ))
then
rvm_warn "gemset $rvm_gemset_name is not existing, creating."
"$rvm_scripts_path/gemsets" create "$rvm_gemset_name"
else
rvm_error "Gemset '${rvm_expected_gemset_name}' does not exist, 'rvm gemset create ${rvm_expected_gemset_name}' first, or append '--create'."
return 2
fi
fi
export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC
GEM_HOME="$rvm_ruby_gem_home"
GEM_PATH="$rvm_ruby_gem_path"
MY_RUBY_HOME="$rvm_ruby_home"
RUBY_VERSION="$rvm_ruby_string"
IRBRC="$rvm_ruby_irbrc"
unset BUNDLE_PATH # Ensure that BUNDLE_PATH is not set!
# Handle MagLev pre-installed gems
if [[ "maglev" == "$rvm_ruby_interpreter" ]]
then
GEM_PATH="$GEM_PATH:$MAGLEV_HOME/lib/maglev/gems/1.8/"
fi
[[ -n "${IRBRC:-}" ]] || unset IRBRC
# Ensure the environment file for the selected ruby exists.
__rvm_ensure_has_environment_files
if (( ${rvm_verbose_flag:=0} == 1 ))
then
rvm_log "Using ${GEM_HOME/${rvm_gemset_separator:-'@'}/ with gemset }"
fi
if [[ "$GEM_HOME" != "$rvm_ruby_global_gems_path" ]]
then
new_path="$GEM_HOME/bin:$rvm_ruby_global_gems_path/bin:$MY_RUBY_HOME/bin:${rvm_bin_path}:$(__rvm_remove_rvm_from_path ;printf "%b" "$PATH")"
else
new_path="$GEM_HOME/bin:$MY_RUBY_HOME/bin:${rvm_bin_path}:$(__rvm_remove_rvm_from_path ;printf "%b" "$PATH")"
fi
fi
[[ -z "${rvm_ruby_string:-}" ]] || export rvm_ruby_string
[[ -z "${rvm_gemset_name:-}" ]] || export rvm_gemset_name
if [[ -n "$new_path" ]]
then
export PATH="$new_path"
unset new_path
builtin hash -r
fi
if [[ "$rvm_ruby_string" != "system" ]]
then
case "${rvm_rvmrc_flag:-0}" in
(rvmrc|versions_conf|ruby_version)
__rvm_set_${rvm_rvmrc_flag}
;;
esac
typeset environment_id
environment_id="$(__rvm_env_string)"
if (( ${rvm_default_flag:=0} == 1 )) &&
[[ "default" != "${rvm_ruby_interpreter:-}" ]] &&
[[ "system" != "${rvm_ruby_interpreter:-}" ]]
then
# Switch the default alias to the new environment id
"$rvm_scripts_path/alias" delete default &> /dev/null
"$rvm_scripts_path/alias" create default "$environment_id" >& /dev/null
fi
rvm_default_flag=0
if [[ -n "${rvm_wrapper_name:-}" ]]
then
"$rvm_scripts_path/wrapper" "$environment_id" "$rvm_wrapper_name" > /dev/null 2>&1
rvm_wrapper_name=""
fi
if [[ -n "${rvm_ruby_alias:-}" ]]
then
rvm_log "Attempting to alias $environment_id to $rvm_ruby_alias"
"$rvm_scripts_path/alias" delete "$rvm_ruby_alias" > /dev/null 2>&1
rvm_alias_expanded=1 "$rvm_scripts_path/alias" create "$rvm_ruby_alias" "$environment_id" > /dev/null 2>&1
ruby_alias="" ; rvm_ruby_alias=""
fi
if [[ "maglev" == "${rvm_ruby_interpreter:-""}" ]]
then
export MAGLEV_HOME="$rvm_ruby_home"
export GEMSTONE_GLOBAL_DIR=$MAGLEV_HOME
if [[ -x "$MAGLEV_HOME/gemstone/bin/gslist" ]]
then
"$MAGLEV_HOME/gemstone/bin/gslist" -clv > /dev/null 2>&1 ; result=$?
if (( result == 1 ))
then
"$rvm_ruby_home/bin/maglev" start
fi
fi
fi
else
if (( ${rvm_default_flag:=0} == 1 ))
then
if ! builtin command -v __rvm_reset >> /dev/null 2>&1
then
source "$rvm_scripts_path/functions/reset"
__rvm_reset
fi
fi
fi
rvm_hook="after_use"
source "$rvm_scripts_path/hook"
return 0
}
__rvm_ruby_string()
{
# rvm_ruby_string may designate any of the following items:
# * rvm_gemset_name
# * rvm_ruby_interpreter
# * rvm_ruby_version
# * rvm_ruby_patch_level
# * rvm_ruby_revision
# * rvm_ruby_tag
typeset ruby_string gemset_name expanded_alias_name repo_url branch_name ruby_name
__rvm_default_flags
rvm_expanding_aliases=
true \
"${rvm_ruby_version:=}" "${rvm_gemset_name:=}" "${rvm_ruby_interpreter:=}"\
"${rvm_ruby_version:=}" "${rvm_ruby_tag:=}" "${rvm_ruby_patch_level:=}"\
"${rvm_ruby_revision:=}" ${rvm_gemset_separator:="@"} "${rvm_ruby_string:=}"\
${rvm_expanding_aliases:=0} ${rvm_head_flag:=0}
if echo "$rvm_ruby_string" | GREP_OPTIONS="" \grep "${rvm_gemset_separator}" >/dev/null 2>&1
then
rvm_gemset_name="${rvm_ruby_string/*${rvm_gemset_separator}/}"
rvm_ruby_string="${rvm_ruby_string/${rvm_gemset_separator}*/}"
fi
# Alias'd rubies
if (( rvm_expanding_aliases == 0 )) &&
[[ -n "${rvm_ruby_string}" && "$rvm_ruby_string" != "system" ]]
then
if expanded_alias_name="$("$rvm_scripts_path/alias" show "$rvm_ruby_string" 2>/dev/null)" \
&& [[ -n "$expanded_alias_name" ]]
then
rvm_ruby_string="$expanded_alias_name"
elif [[ "$rvm_ruby_string" == default ]]
then
# Default is not a known value. Instead, we need to therefore set it to system.
rvm_ruby_string="system"
fi
fi
if echo "$rvm_ruby_string" | GREP_OPTIONS="" \grep "${rvm_gemset_separator}" >/dev/null 2>&1 ; then
rvm_gemset_name="${rvm_ruby_string/*${rvm_gemset_separator}/}"
rvm_ruby_string="${rvm_ruby_string/${rvm_gemset_separator}*/}"
fi
# Stash the ruby string.
ruby_string="${rvm_ruby_string:-}"
gemset_name="${rvm_gemset_name:-}"
repo_url="${rvm_ruby_repo_url:-}"
branch_name="${rvm_ruby_repo_branch:-}"
ruby_name="${rvm_ruby_name:-}"
__rvm_unset_ruby_variables
rvm_ruby_repo_url="${repo_url:-}"
rvm_ruby_repo_branch="${branch_name:-}"
rvm_ruby_name="$ruby_name"
if [[ -n "$gemset_name" ]]
then
rvm_gemset_name="$gemset_name"
rvm_sticky_flag=1 # <- not sold on this.
fi
strings=($(echo ${ruby_string//-/ }))
if (( ${#strings[@]} == 0 ))
then
if echo "${GEM_HOME:-}" | GREP_OPTIONS="" \grep "${rvm_path}" >/dev/null 2>&1
then
# Current Ruby
strings="${GEM_HOME##*\/}"
strings="${strings/%${rvm_gemset_separator:-"@"}*}"
rvm_ruby_string="$strings"
strings=( $(echo ${rvm_ruby_string//-/ }) )
else
strings=(system)
rvm_ruby_string="system"
fi
fi
for string in ${strings[@]}
do
case "$string" in
(head)
rvm_ruby_patch_level=""
rvm_ruby_revision=""
rvm_ruby_tag=""
export rvm_head_flag=1
;;
(system)
rvm_ruby_interpreter="system"
rvm_ruby_patch_level=""
rvm_ruby_tag=""
rvm_ruby_revision=""
rvm_ruby_version=""
rvm_gemset_name=""
rvm_head_flag=0
return 0
;;
(ext|external)
rvm_ruby_interpreter="ext"
rvm_ruby_patch_level=""
rvm_ruby_tag=""
rvm_ruby_revision=""
rvm_ruby_version=""
rvm_head_flag=0
unset strings[__array_start]
strings=( ${strings[@]} )
strings="${strings[*]}"
rvm_ruby_name="${strings// /-}"
break
;;
(nightly)
rvm_ruby_version="nightly"
rvm_nightly_flag=1
break
;;
(preview*)
rvm_ruby_patch_level="$string"
;;
(rc[[:digit:]]*)
rvm_ruby_patch_level="$string"
;;
([[:digit:]].[[:digit:]]*)
#TODO: use normal code for rbx!
if [[ "${rvm_ruby_interpreter}" == "rbx" ]]
then
if [[ -z "${rvm_ruby_version}" ]]
then
rvm_ruby_version="${string}"
elif [[ -z "${rvm_ruby_patch_level}" ]]
then
rvm_ruby_patch_level="${string}"
else
rvm_error "Unknown ruby interpreter string component: '$string'."
return 1
fi
else
case "$string" in
(0.+([[:digit:]])|0.+([[:digit:]]).+([[:digit:]])|1.+([[:digit:]]).+([[:digit:]])|2.+([[:digit:]]).+([[:digit:]])|1.+([[:digit:]]).+([[:digit:]]).+([[:digit:]])|1.+([[:digit:]]))
rvm_ruby_version="$string"
rvm_ruby_revision=""
rvm_ruby_tag=""
;;
(1.+([[:digit:]]).+([[:digit:]]).+([[:alnum:]]))
case "${rvm_ruby_interpreter:-""}" in
(jruby)
rvm_ruby_version="$string"
;;
(*)
rvm_error "Unknown ruby interpreter version: '$string'."
return 1
;;
esac
;;
(*)
rvm_error "Unknown ruby interpreter version: '$string'."
return 1
;;
esac
fi
;;
(p[[:digit:]]*)
rvm_ruby_patch_level="$string"
;;
([[:digit:]][[:digit:]]*)
case "${rvm_ruby_interpreter:-""}" in
(ree)
rvm_ruby_patch_level="$string"
rvm_ruby_revision=""
;;
(kiji)
rvm_ruby_patch_level="$string"
rvm_ruby_revision=""
;;
(rbx)
rvm_ruby_patch_level="$string"
;;
(maglev)
rvm_ruby_version="$string"
rvm_ruby_revision=""
rvm_ruby_patch_level=""
;;
(*)
rvm_ruby_revision="r$string"
;;
esac
;;
(r[[:digit:]]*)
rvm_ruby_patch_level=""
rvm_ruby_revision="$string"
;;
(s[[:alnum:]]*)
rvm_ruby_revision=""
rvm_ruby_sha="${string#s}"
;;
(tv[[:digit:]]*|t[[:digit:]]*)
rvm_ruby_patch_level="" ; rvm_ruby_revision=""
rvm_ruby_tag="$string"
;;
(m[[:digit:]]*)
rvm_ruby_mode="$string"
;;
(u[[:alnum:]]*)
rvm_ruby_patch_level="" ; rvm_ruby_revision="" ; rvm_ruby_tag="" ; rvm_ruby_patch=""
rvm_ruby_user_tag="$string"
;;
(a[[:digit:]][[:digit:]]*)
rvm_ruby_bits="$string" # Architecture
;;
(b[[:digit:]]*)
rvm_ruby_repo_branch="${string}"
rvm_head_flag=1
;;
(ruby|rbx|jruby|macruby|ree|kiji|rubinius|maglev|ironruby|goruby|tcs)
rvm_ruby_interpreter="$string"
;;
([[:alpha:]]*([[:alnum:]]|_))
rvm_ruby_name="$string"
;;
(*)
rvm_error "Unknown ruby interpreter string component: '$string'."
return 1
;;
esac
done
if [[ -z "${rvm_ruby_interpreter:-""}" ]]
then
# Detect interpreter based on version.
case "$rvm_ruby_version" in
(1.[8-9]*) rvm_ruby_interpreter="ruby" ;;
(0.[5-6]*) rvm_ruby_interpreter="macruby" ;;
(1.[0-4]*) rvm_ruby_interpreter="rbx" ;;
(1.[5-7]*) rvm_ruby_interpreter="jruby" ;;
(2.*)
rvm_error "Version '$rvm_ruby_version' is to confusing to select ruby interpreter."
return 2
;;
esac
fi
# Unspecified version
rvm_ruby_version="${rvm_ruby_version:-}"
if [[ -z "${rvm_ruby_version:-}" && "${rvm_ruby_interpreter}" != "ext" ]] && (( ${rvm_head_flag:=0} == 0 ))
then
rvm_ruby_version="${rvm_ruby_version:-"$(
__rvm_db "${rvm_ruby_interpreter}_version"
)"}"
fi
if [[ -z "${rvm_ruby_version:-}" ]]
then
rvm_ruby_string="${rvm_ruby_interpreter}"
else
rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}"
fi
if [[ "${rvm_ruby_interpreter}" == "ext" ]]
then
true # skip checking for external rubies
elif (( ${rvm_head_flag:=0} == 1 ))
then
rvm_ruby_string="${rvm_ruby_string}-head"
elif [[ -n "${rvm_ruby_revision:-}" ]]
then
rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_revision}"
elif [[ -n "${rvm_ruby_sha:-}" ]]
then
rvm_ruby_string="${rvm_ruby_string}-s${rvm_ruby_sha}"
elif [[ -n "${rvm_ruby_tag:-}" ]]
then
rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_tag}"
elif [[ -n "${rvm_ruby_patch_level:-}" ]]
then
rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_patch_level}"
elif [[ -n "${rvm_ruby_user_tag:-}" ]]
then
rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_user_tag}"
else
patch_level="$(
__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_patch_level"
)"
if [[ -n "${patch_level:-""}" ]]
then
case "$rvm_ruby_interpreter" in
ree|kiji|rbx)
# REE, Kiji & Rubinius use dates for their patch levels.
rvm_ruby_patch_level="${patch_level}"
;;
*)
# MRI uses -pN+ to specify the patch level.
rvm_ruby_patch_level="p${patch_level}"
;;
esac
fi
if [[ -n "${rvm_ruby_patch_level:-""}" ]]
then
rvm_ruby_patch_level="${rvm_ruby_patch_level/#pp/p}"
rvm_ruby_patch_level="${rvm_ruby_patch_level/#prc/rc}"
rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_patch_level}"
case "$rvm_ruby_interpreter" in
(ree|kiji|rbx)
rvm_ruby_string="${rvm_ruby_string//-p*/-}"
;;
(*)
rvm_ruby_string="${rvm_ruby_string//-pp/-p}"
rvm_ruby_string="${rvm_ruby_string//-prc/-rc}"
;;
esac
fi
fi
if [[ -n "${rvm_ruby_name:-}" ]]
then
rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_name}"
# record the name for validation of -n option
detected_rvm_ruby_name="${rvm_ruby_name}"
# clean the name so it is not added again (rbx -n install problem)
rvm_ruby_name=""
else
# record the no name for validation of -n option
detected_rvm_ruby_name=""
fi
}
__rvm_ruby_strings_exist()
{
for rvm_ruby_string in ${@//,/ }
do
rvm_verbose_flag=0 __rvm_use "${rvm_ruby_string}" >/dev/null 2>&1 || return $?
printf "%b" "${rvm_ruby_string}${rvm_gemset_name:+@}${rvm_gemset_name:-}\n"
done
unset rvm_ruby_string
}