forked from rvm/rvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist
executable file
·303 lines (263 loc) · 6.7 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
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
#!/usr/bin/env bash
rvm_base_except="selector"
source "$rvm_scripts_path/base"
source "$rvm_scripts_path/functions/list"
__rvm_list_remote()
{
\typeset version
rubies=($(
__list_remote_all |
__rvm_sed -e 's/.tar.*$//' -e 's/jruby-bin-/jruby-/' |
__rvm_awk -F/ '{print $NF}' |
\command \sort -u
))
if
(( ${#rubies[@]} == 0 ))
then
rvm_error "
# No remote rubies available
# Check 'rvm list known' for what can be installed.
"
return 1
fi
printf "%b" "\n# Remote rubies available:\n\n"
for version in "${rubies[@]}"
do
if [[ -r "$rvm_rubies_path/$version/bin/ruby" ]]
then rvm_log " * $version"
else rvm_log " $version"
fi
done
rvm_log "\n<comment># * - installed already</comment>\n"
rvm_log "<comment># To download and install:</comment> <code>rvm install {name} --binary</code>\n\n"
}
__rvm_list_detect_arch()
{
if
[[ -d "$rvm_gems_path/${__version}" && ! -d "$rvm_rubies_path/${__version%%@*}" ]]
then
__arch="ruby not installed"
elif
[[ ! -x "$rvm_rubies_path/${__version%%@*}/bin/ruby" ]]
then
__arch="missing bin/ruby"
elif
[[ -f "$rvm_rubies_path/${__version%%@*}/config" ]]
then
__arch="$(
__rvm_awk -F= "\$1==\"target_cpu\" {gsub(/[\"']/,\"\"); print \$2}" < \
$rvm_rubies_path/${__version%%@*}/config
)" #'
else
__arch="$( __rvm_ruby_config_get "target_cpu" "$rvm_rubies_path/${__version%%@*}/bin/ruby" )"
fi
if
[[ -z "${__arch}" ]]
then
case "${__version}" in
(maglev-*|macruby-*) __arch="x86_64" ;;
(mruby|mruby-*) __arch="x86_64" ;;
(*) __arch="broken" ;;
esac
fi
}
__rvm_list_show_version_with_arch()
{
\typeset __arch __prefix __version __suffix
__prefix="$1"
__version="$2"
__suffix="${3:-}"
__rvm_list_detect_arch
if rvm_pretty_print stdout
then __version="${rvm_notify_clr:-}${__version}${rvm_reset_clr:-}"
fi
printf "%b" "${__prefix}${__version} [ ${__arch} ]${__suffix}"
}
__rvm_list_gemsets()
{
\typeset all_rubies version versions ruby_version_name current_ruby selected system_ruby system_version string binary prefix
if [[ "${1:-""}" == "strings" ]]
then
__rvm_list_gemset_strings
return 0
fi
current_ruby="$(__rvm_env_string)"
all_rubies="$(__rvm_list_strings | sort)"
printf "%b" "\nrvm gemsets\n"
versions=($(
__rvm_cd "${rvm_gems_path:-"$rvm_path/gems"}/"
__rvm_find . -maxdepth 1 -mindepth 1 -print 2> /dev/null |
__rvm_awk '/[a-z]*-.*/ {print $NF}' | sort
))
for version in "${versions[@]//.\/}"
do
ruby_version_name="$(echo "$version" | __rvm_awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')"
if [[ "$all_rubies" != *"$ruby_version_name"* ]]
then continue
fi
if [[ "$version" == "$current_ruby" ]]
then prefix="=> "
else prefix=" "
fi
__rvm_list_show_version_with_arch "\n${prefix}" "$version"
done
if [[ -f "$rvm_path/config/default" && -s "$rvm_path/config/default" ]]
then
version=$(
__rvm_grep 'MY_RUBY_HOME' "$rvm_path/config/default" |
\command \head -1 | __rvm_awk -F"'" '{print $2}' | __rvm_xargs basename --
)
if
[[ -n "$version" ]]
then
printf "%b" "\nDefault Ruby (for new shells)\n"
__rvm_list_show_version_with_arch "\n " "$version" "\n"
fi
fi
printf "%b" "\n\n"
return 0
}
__rvm_list_default()
{
\typeset version string
if
[[ "$1" == "string" ]]
then
"$rvm_scripts_path/alias" show default 2>/dev/null |
__rvm_awk -F"${rvm_gemset_separator:-"@"}" '{print $1}' |
__rvm_xargs basename --
else
if
[[ -L "$rvm_rubies_path/default" ]]
then
version=$(
"$rvm_scripts_path/alias" show default 2>/dev/null |
__rvm_awk -F"${rvm_gemset_separator:-"@"}" '{print $1}' |
__rvm_xargs basename --
)
if
[[ -n "$version" ]]
then
printf "%b" "\nDefault Ruby (for new shells)\n"
__rvm_list_show_version_with_arch "\n " "$version" "\n"
fi
fi
fi
printf "%b" "\n"
return 0
}
__rvm_list_ruby_svn_tags()
{
\typeset -a tags
\typeset prefix tag
__rvm_read_lines tags <(
svn list http://svn.ruby-lang.org/repos/ruby/tags/ | __rvm_awk '/^v1_[8|9]/{print}'
)
for tag in "${tags[@]}"
do
prefix="$(
echo ${tag/\//} |
__rvm_sed 's#^v1_##' |
__rvm_awk -F'_' '{print "(ruby-)1."$1"."$2}' |
__rvm_sed 's#p$##'
)"
echo "${prefix}-t${tag/\//}"
done
return 0
}
__rvm_list_known()
{
if [[ "${1:-""}" == "strings" ]]
then
__rvm_list_known_strings
return 0
fi
if [[ -t 0 ]]
then
__rvm_pager_or_cat_v "$rvm_path/config/known"
else
\command \cat "$rvm_path/config/known"
fi
return $?
}
__rvm_list_rubies()
{
\typeset current_ruby rubies version selected system_ruby system_version \
default_ruby string binary prefix
if [[ "${1:-""}" == "strings" ]]
then
__rvm_list_strings
return 0
fi
current_ruby="$( __rvm_env_string )"
current_ruby="${current_ruby%${rvm_gemset_separator:-"@"}*}"
default_ruby="$( "$rvm_scripts_path/alias" show default 2>/dev/null )"
default_ruby="${default_ruby%${rvm_gemset_separator:-"@"}*}"
rubies=($(
__rvm_cd "$rvm_rubies_path/"
__rvm_find . -maxdepth 1 -mindepth 1 -type d 2> /dev/null | sort
))
for version in "${rubies[@]//.\/}"
do
if
[[ "$version" == "$current_ruby" && "$version" == "$default_ruby" ]]
then
prefix="=* "
elif
[[ "$version" == "$current_ruby" ]]
then
prefix="=> "
elif
[[ "$version" == "$default_ruby" ]]
then
prefix=" * "
else
prefix=" "
fi
__rvm_list_show_version_with_arch "${prefix}" "$version" "\n"
done
if (( ${#rubies[@]} == 0 ))
then
printf "%b" "
# No rvm rubies installed yet. Try 'rvm help install'.
"
else
if [[ -z "${default_ruby}" ]]
then
printf "%b" "
# Default ruby not set. Try 'rvm alias create default <ruby>'.
"
fi
printf "%b" "
# => - current
# =* - current && default
# * - default
"
fi
printf "%b" "\n"
return 0
}
# 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.
__rvm_list()
{
\typeset action="${1:-rubies}"
shift
case "${action}" in
-r|--remote|remote)
__rvm_list_remote "$@"
;;
known|known_strings|gemsets|default|rubies|strings|ruby_svn_tags)
__rvm_list_${action} "$@"
;;
help)
rvm_help list "${action}" "$@"
;;
*)
rvm_error_help "Unknown action '$action' for 'rvm list'." list "${action}" "$@"
return 1
;;
esac
}
__rvm_list "$@"