/
rvm-shell
executable file
·93 lines (83 loc) · 2.17 KB
/
rvm-shell
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
#!/usr/bin/env bash
export HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
do
if [[ -f "$rvmrc" ]]
then
if GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
then
printf "%b" "\nError: $rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc"
return 1
else
source "$rvmrc"
fi
fi
done
fi
export rvm_path
if [[ -z "${rvm_path:-}" ]]
then
if (( UID == 0 )) && [[ -d "/usr/local/rvm" ]]
then rvm_path="/usr/local/rvm"
elif [[ -d "${HOME}/.rvm" ]]
then rvm_path="${HOME}/.rvm"
elif [[ -d "/usr/local/rvm" ]]
then rvm_path="/usr/local/rvm"
else echo "Can't find rvm install!" 1>&2 ; exit 1
fi
fi
true ${rvm_scripts_path:="$rvm_path/scripts"}
__rvm_shell_lookup_script()
{
local relative_scripts_dir directory
if [[ -L $0 ]]
then relative_scripts_dir="$(dirname -- "$(dirname -- "$( readlink "$0")" )" )/scripts" #"
else relative_scripts_dir="$(dirname -- "$(dirname -- "$0")")/scripts" #"
fi
for directory in "$rvm_scripts_path" "$HOME/.rvm/scripts" "/usr/local/rvm/scripts" "$relative_scripts_dir"
do
if [[ -d "$directory" && -s "$directory/rvm" ]]
then
echo "$directory/rvm"
return
fi
done
}
case $0 in
(*-rvm-env) selected_shell=${0%-rvm-env} ;;
(*) selected_shell=bash ;;
esac
selected_shell="$(basename "${selected_shell}")"
if [[ -n "$1" && ! -f "$1" && -n "$(echo "$1" | GREP_OPTIONS="" \grep -v '^-')" ]]
then
rvm_shell_ruby_string="$1"
shift
elif [[ "$1" == "--path" && "$2" =~ /* ]]
then
if [[ -d "$2" ]]
then
cd $2
else
rvm_shell_ruby_string="default"
fi
shift 2
fi
rvm_shell_rvm_path="$(__rvm_shell_lookup_script)"
if [[ -n "$rvm_shell_rvm_path" ]]
then
source "$rvm_shell_rvm_path"
# Setup as expected.
if [[ -n "$rvm_shell_ruby_string" ]]
then
if ! rvm "$rvm_shell_ruby_string"
then
echo "Error: RVM was unable to use '$rvm_shell_ruby_string'" 1>&2
exit 1
fi
else
rvm rvmrc load >/dev/null 2>&1
fi
fi
exec ${selected_shell} "$@"