/
rvmrc
179 lines (154 loc) · 4.59 KB
/
rvmrc
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
#!/usr/bin/env bash
source "${rvm_scripts_path}/functions/rvmrc_env"
source "${rvm_scripts_path}/functions/rvmrc_project"
source "${rvm_scripts_path}/functions/rvmrc_set"
source "${rvm_scripts_path}/functions/rvmrc_to"
source "${rvm_scripts_path}/functions/rvmrc_trust"
source "${rvm_scripts_path}/functions/rvmrc_warning"
__rvm_rvmrc_match_all() [[ "${1:-}" == "all" || "${1:-}" == "all.rvmrcs" || "${1:-}" == "allGemfiles" ]]
__rvm_rvmrc_tools()
{
\typeset rvmrc_action rvmrc_warning_action rvmrc_path saveIFS trust rvmrc_ruby
rvmrc_action="$1"
(( $# )) && shift || true
if
[[ "${rvmrc_action}" == "warning" ]]
then
rvmrc_warning_action="${1:-}"
(( $# )) && shift || true
fi
if
[[ "${rvmrc_action}" == "create" ]]
then
rvmrc_ruby="${1:-${GEM_HOME##*/}}"
rvmrc_path="$(__rvm_cd "$PWD" >/dev/null 2>&1; pwd)/${2:-.rvmrc}"
elif
[[ "$1" == ".rvmrc" ]]
then
rvmrc_path="$PWD/.rvmrc"
elif
[[ "${rvmrc_action}" == "to" || "${rvmrc_action}" == "warning" ]] ||
[[ -n "${1:-}" ]]
then
rvmrc_path="$1"
else
rvmrc_path="$PWD/.rvmrc"
fi
if
[[ "${rvmrc_action}" == "to" ||
"${rvmrc_action}" == "warning" ||
"${rvmrc_action}" == "create"
]]||
__rvm_rvmrc_match_all "${rvmrc_path:-}" # ignore all*
then
true
else
__rvm_project_dir_check "${rvmrc_path}" rvmrc_path "${rvmrc_path}/.rvmrc"
fi
rvmrc_path="${rvmrc_path//\/\///}"
rvmrc_path="${rvmrc_path%/}"
case "$rvmrc_action" in
warning)
__rvmrc_warning "${rvmrc_warning_action:-}" "$rvmrc_path" || return $?
;;
to)
__rvm_rvmrc_to "$rvmrc_path" || return $?
;;
create)
(
rvm_create_flag=1 __rvm_use "${rvmrc_ruby}"
case "${rvmrc_path}" in
(*/.rvmrc|*/--rvmrc) __rvm_set_rvmrc ;;
(*/.ruby-version|*/--ruby-version) __rvm_set_ruby_version ;;
(*/.versions.conf|*/--versions-conf) __rvm_set_versions_conf ;;
(*)
rvm_error "Unrecognized project file format."
return 1
;;
esac
)
;;
reset)
__rvm_reset_rvmrc_trust "$rvmrc_path" &&
rvm_log "Reset trust for $rvmrc_path" ||
rvm_error "Reset trust for $rvmrc_path - failed"
;;
trust)
__rvm_trust_rvmrc "$rvmrc_path" &&
rvm_log "Marked $rvmrc_path as trusted" ||
rvm_error "Marked $rvmrc_path as trusted - failed"
;;
untrust)
__rvm_untrust_rvmrc "$rvmrc_path" &&
rvm_log "Marked $rvmrc_path as untrusted" ||
rvm_error "Marked $rvmrc_path as untrusted - failed"
;;
trusted)
__rvm_rvmrc_stored_trust_check "$rvmrc_path" || return $?
;;
is_trusted)
__rvm_rvmrc_stored_trust_check "$rvmrc_path" >/dev/null
;;
load)
rvm_current_rvmrc="" rvm_trust_rvmrcs_flag=1 __rvm_project_rvmrc "${rvmrc_path%/.rvmrc}"
;;
try_to_read_ruby)
__rvm_rvmrc_tools_try_to_read_ruby "$@" || return $?
;;
*)
rvm_error "Usage: rvm rvmrc {trust,untrust,trusted,load,reset,is_trusted,try_to_read_ruby,create}"
return 1
;;
esac
return $?
}
__rvm_rvmrc_tools_try_to_read_ruby()
{
case "$rvmrc_path" in
(*/.rvmrc)
# make sure the flag is passed on to sub-process () / $()
if [[ -n "${rvm_trust_rvmrcs_flag:-}" ]]
then export rvm_trust_rvmrcs_flag
fi
rvmrc_path="$(cd "$(dirname "$rvmrc_path")"; pwd)/.rvmrc"
__rvm_rvmrc_tools is_trusted "$(dirname "$rvmrc_path")" .rvmrc ||
(
# subprocess to not mess with current process variables
rvm_promptless=1 __rvm_project_rvmrc "$rvmrc_path" >/dev/null 2>&1
)
if __rvm_rvmrc_tools is_trusted "$(dirname "$rvmrc_path")" .rvmrc
then __rvm_rvmrc_tools_read_ruby "$@" || return $?
else return 1
fi
;;
(*)
__rvm_rvmrc_tools_read_ruby "$@" || return $?
;;
esac
}
__rvm_save_variables()
{
\typeset __save_to __key
__save_to="$1"
shift
for __key in "$@"
do
eval "${__save_to}+=( \"\${__key}=\${${__key}}\" )"
done
}
__rvm_rvmrc_tools_read_ruby()
{
\typeset __result
\typeset -a rvmrc_tools_read_ruby
rvmrc_tools_read_ruby=()
__rvm_save_variables rvmrc_tools_read_ruby \
rvm_current_rvmrc result current_result rvm_token next_token \
rvm_action _string
rvm_current_rvmrc=""
rvm_action="${rvm_action:-use}" rvm_trust_rvmrcs_flag=1 __rvm_project_rvmrc "$rvmrc_path" >/dev/null &&
rvm_ruby_string="${GEM_HOME##*/}" &&
rvm_ruby_strings="$rvm_ruby_string" ||
__result=101
__rvm_set_env "" "${rvmrc_tools_read_ruby[@]}"
return ${__result:-0}
}