-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
list
executable file
·102 lines (90 loc) · 3.66 KB
/
list
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
#!/usr/bin/env bash
if [[ "$rvm_trace_flag" -eq 2 ]] ; then set -x ; export rvm_trace_flag ; fi
# Query for valid rvm ruby strings
# This is meant to be used with scripting.
list_strings() {
echo $(\ls $rvm_rubies_path)
}
list_default() {
strings="$(echo $rvm_ruby_args | awk '{print $2}')"
if [[ "$strings" = "string" ]] ; then
$rvm_scripts_path/alias show default 2>/dev/null | awk -F"$rvm_gemset_separator" '{print $1}' | xargs basename
else
if [[ -L "$rvm_rubies_path/default" ]]; then
version=$($rvm_scripts_path/alias show default 2>/dev/null | awk -F"$rvm_gemset_separator" '{print $1}' | xargs basename)
if [[ ! -z "$version" ]] ; then
printf "\n\nDefault Ruby (for new shells)\n"
string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
printf "\n $(tput setaf 2)$version$(tput sgr0) $string\n"
fi ; unset version
fi
fi
}
list_ruby_svn_tags() {
while read -r tag
do
prefix="$(echo ${tag/\//} | sed 's#^v1_##' | awk -F'_' '{print "(ruby-)1."$1"."$2}' | sed 's#p$##')"
echo "${prefix}-t${tag/\//}"
unset prefix tag
done < <(svn list http://svn.ruby-lang.org/repos/ruby/tags/ | awk '/^v1_[8|9]/')
}
list_known() {
if [[ -z "$rvm_interactive" ]] || [[ -z "$TERM" ]] || [[ "unknown" = "$TERM" ]] ; then
cat "$rvm_config_path/known"
else
cat "$rvm_config_path/known" | ${PAGER:-less}
fi
}
list_rubies() {
echo
ruby=$(command -v ruby) ; current_ruby=""
if [[ ! -z "$ruby" ]] && [[ ! -z "$(echo $ruby | awk '/rvm/')" ]] ; then
current_ruby="$(echo $ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null)"
fi
printf "rvm rubies\n"
for version in $(\ls $rvm_rubies_path/ 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}') ; do
if [[ ! -z "$(echo $version | awk '/^jruby-/')" ]] ; then
string="[ $($rvm_rubies_path/$version/bin/ruby -v | awk '{print $NF}') ]"
elif [[ ! -z "$(echo $version | awk '/^maglev-|^macruby-/')" ]] ; then
string="[ x86_64 ]"
else
string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
fi
printf "\n"
if [[ "$version" = "$current_ruby" ]]; then
printf "=> "
else
printf " "
fi
printf "$(tput setaf 2)$version$(tput sgr0) $string"
done ; unset version
if [[ -f "$rvm_config_path/default" ]] && [[ -s $rvm_config_path/default ]] ; then
version=$(grep 'MY_RUBY_HOME' $rvm_config_path/default | head -n 1 | awk -F"'" '{print $2}' | xargs basename)
if [[ ! -z "$version" ]] ; then
printf "\n\nDefault Ruby (for new shells)\n"
string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
printf "\n $(tput setaf 2)$version$(tput sgr0) $string"
fi ; unset version
fi
printf "\n"
unset current_ruby version selected system_ruby system_version string binary
echo
}
# List all rvm installed rubies, default ruby and system ruby.
# Display the rubies, indicate their architecture and indicate which is currently used.
# This is not meant to be used with scripting. This is for interactive mode usage only.
action="$(echo "$1" | awk '{print $1}')"
if [[ "known" = "$action" ]] ; then
list_known
elif [[ "default" = "$action" ]] ; then
list_default
elif [[ -z "$action" ]] || [[ "rubies" = "$action" ]] ; then
list_rubies
elif [[ "strings" = "$action" ]] ; then
list_strings
elif [[ "ruby_svn_tags" = "$action" ]] ; then
list_ruby_svn_tags
else # help
printf "\nUsage: rvm list {known,default,rubies,strings}"
fi
exit $?