-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
wrapper
executable file
·61 lines (47 loc) · 1.76 KB
/
wrapper
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
#!/usr/bin/env bash
# Recursive loops, oh my!
unset rvm_default_flag
source $rvm_scripts_path/initialize
source $rvm_scripts_path/utility
source $rvm_scripts_path/selector
if [[ ! -z "$rvm_trace_flag" ]] ; then set -x ; export rvm_trace_flag ; fi
trap "if [[ -d $rvm_tmp_path/ ]] && [[ -s $rvm_tmp_path/$$ ]] ; then rm -f $rvm_tmp_path/$$ > /dev/null 2>&1 ; fi ; exit" 0 1 2 3 15
wrap() {
printf "#!/usr/bin/env sh\n" > "$file_name"
printf ". \"${rvm_environments_path}/$(__rvm_environment_identifier)\"\n" >> "$file_name"
printf "exec $binary_name \"\$@\"" >> "$file_name"
if [[ -f $file_name ]] ; then chmod +x $file_name ; fi
}
usage() {
printf "Usage: 'rvm wrapper [ruby_string] [wrapper_prefix] [binary[ binary[ ...]]]'\n"
printf " Where binary defaults to ruby, gem, rake, irb, rdoc, ri, testrb\n"
printf " For more information, see 'rvm help wrapper'\n"
}
args="$*"
ruby_string="$(echo "$args" | awk '{print $1}')"
prefix="$(echo "$args" | awk '{print $2}')"
binaries=$(echo "$args" | awk '{$1="" ; $2=""; print}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ -z "$ruby_string" ]]; then
usage ; exit 1
fi
if [[ -z "$binaries" ]] ; then
# TODO: Extract out into a rvm_ variable.
binaries="ruby gem irb ri rdoc rake erb testrb"
fi
rvm_ruby_string="${ruby_string}" ; __rvm_select ; __rvm_use
for binary_name in $(echo $binaries); do
if [[ -z "$prefix" ]] ; then
file_name="${rvm_bin_path}/${binary_name}"
else
file_name="${rvm_bin_path}/${prefix}_${binary_name}"
fi
if command -v $binary_name > /dev/null; then
wrap
else
$rvm_scripts_path/log "error" "Binary '$binary_name' not found in path."
fi
unset file_name
done
unset rvm_ruby_string args ruby_string prefix binaries
__rvm_unset_ruby_variables
exit $?