-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
info
executable file
·245 lines (220 loc) · 5.55 KB
/
info
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
#!/usr/bin/env bash
if
[[ "$rvm_trace_flag" -eq 2 ]]
then
set -x
export rvm_trace_flag
fi
source "$rvm_scripts_path/base"
source "$rvm_scripts_path/version"
version_for()
{
typeset binary
binary=${1:-""}
if
builtin command -v "$binary" >/dev/null
then
$binary --version | head -n1
else
echo "not installed"
fi
}
info_system()
{
rvm_info="
system:
uname: \"$(uname -a)\"
system: \"$(__rvm_system_path - )\"
bash: \"$(command -v bash) => $(version_for bash)\"
zsh: \"$(command -v zsh) => $(version_for zsh)\"
"
}
print_part()
{
(( $1 )) || return
typeset ret
ret="$1 $2"
(( $1 == 1 )) || ret="${ret}s"
printf "$ret "
}
info_rvm()
{
typeset installed_at years months days hours minutes seconds part
rvm_info="
rvm:
version: \"$(__rvm_version | \tr "\n" ' ' | __rvm_strip)\"
"
rvm_info="${rvm_info} updated: \""
installed_at="$(cat ${rvm_path}/installed.at)"
if
[[ -n "${installed_at:-}" ]] && (( installed_at ))
then
seconds="$(( $(date +%s) - installed_at ))"
if
(( seconds ))
then
minutes="$(( seconds / 60 % 60 ))"
hours="$(( seconds / 3600 % 24 ))"
days="$(( seconds / 86400 % 31 ))"
months="$(( seconds / 2678400 % 12 ))"
years="$(( seconds / 31536000 ))"
seconds="$(( seconds % 60 ))"
for part in year month day hour minute second
do eval "rvm_info=\"\${rvm_info}\$(print_part \${${part}s} ${part})\""
done
rvm_info="${rvm_info}ago"
else
rvm_info="${rvm_info}just now"
fi
else
rvm_info="${rvm_info}can not read installation time\n"
fi
rvm_info="${rvm_info}\"\n"
}
info_ruby()
{
[[ "$(__rvm_env_string)" == "system" ]] && return
ruby=$(builtin command -v ruby)
if
[[ $? -eq 0 ]] && [[ -x "$ruby" ]]
then
full_version="$($ruby -v)"
fi
rvm_info="
ruby:
interpreter: \"$(printf "%b" "${full_version}" | awk '{print $1}')\"
version: \"$(printf "%b" "${full_version}" | awk '{print $2}')\"
date: \"$(printf "%b" "${full_version}" | sed 's/^.*(\([0-9]\{4\}\(-[0-9][0-9]\)\{2\}\).*$/\1/')\"
platform: \"$(printf "%b" "${full_version}" | sed 's/^.*\[//' | sed 's/\].*$//')\"
patchlevel: \"$(printf "%b" "${full_version}" | sed 's/^.*(//' | sed 's/).*$//')\"
full_version: \"${full_version}\"
"
}
info_homes()
{
rvm_info="
homes:
gem: \"${GEM_HOME:-"not set"}\"
ruby: \"${MY_RUBY_HOME:-"not set"}\"
"
}
info_binaries()
{
rvm_info="
binaries:
ruby: \"$(command -v ruby)\"
irb: \"$(command -v irb)\"
gem: \"$(command -v gem)\"
rake: \"$(command -v rake)\"
"
}
info_environment()
{
rvm_info="
environment:
PATH: \"${PATH:-""}\"
GEM_HOME: \"${GEM_HOME:-""}\"
GEM_PATH: \"${GEM_PATH:-""}\"
MY_RUBY_HOME: \"${MY_RUBY_HOME:-""}\"
IRBRC: \"${IRBRC:-""}\"
RUBYOPT: \"${RUBYOPT:-""}\"
gemset: \"$(__rvm_current_gemset)\"\n
"
if [[ -n "${MAGLEV_HOME:-""}" ]]
then rvm_info="$rvm_info\n MAGLEV_HOME: \"$MAGLEV_HOME\""
fi
rvm_info="$rvm_info\n"
}
info_debug()
{
rvm_info="
$(__rvm_version)
$("$rvm_scripts_path/info" "$rvm_ruby_string" "" )
PATH:\n$(printf "%b" "$PATH" | awk -F":" '{print $1":"$2":"$3":"$4":"$5}' )
uname -a: $(uname -a)
permissions: $(\ls -la "$rvm_path" "$rvm_rubies_path")
"
if [[ "Darwin" == "$(uname)" ]]
then
rvm_info="$rvm_info
uname -r: $(uname -r)
uname -m: $(uname -m)
sw_vers: $(sw_vers | \tr "\n" ',')
ARCHFLAGS: ${ARCHFLAGS:-""}
LDFLAGS: ${LDFLAGS:-""}
CFLAGS: ${CFLAGS:-""}
/Developer/SDKs/*:$(/usr/bin/basename -a /Developer/SDKs/* | \tr "\n" ',')
"
fi
for file_name in "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.zshenv"
do
if
[[ -s "$file_name" ]]
then
rvm_info="$rvm_info\n$file_name:\n$(GREP_OPTIONS="" \grep 'rvm' "$file_name" 2>/dev/null || true)"
fi
done
if (( ${rvm_user_install_flag:=0} == 0 ))
then debug_files=("$rvm_path/config/alias" "$rvm_path/config/system" "$rvm_path/config/db" "/etc/rvmrc" "/etc/gemrc")
else debug_files=("$rvm_path/config/alias" "$rvm_path/config/system" "$rvm_path/config/db" "$HOME/.rvmrc" "$HOME/.gemrc")
fi
for file_name in "${debug_files[@]}"
do
if
[[ -f "$file_name" && -s "$file_name" ]]
then
rvm_info="$rvm_info\n$file_name \(filtered\):\n$(awk '!/assword|_key/' "$file_name" )\n"
fi
done
rvm_info="$rvm_info\ngem sources:\n$(gem sources | awk '/gems/')\n\n"
}
info_sections()
{
for section in $(printf "%b" "${sections//,/ }")
do
rvm_info=""
"info_${section}"
printf "%b" "$rvm_info"
done
}
rvm_ruby_gem_home="${rvm_ruby_gem_home:-${GEM_HOME:-""}}"
if
[[ ! -d "$rvm_ruby_gem_home" ]] &&
builtin command -v gem > /dev/null 2>&1
then
rvm_ruby_gem_home="$(gem env home)"
fi
rvm_info=""
args=($*)
ruby_strings="${args[$__array_start]// /}"
args[$__array_start]=""
args=(${args[@]})
sections="${args// /}"
all_sections="system rvm ruby homes binaries environment"
# TODO: Figure out what was the thought here and remove external match script
# dependency
if
__rvm_string_match "$all_sections debug" "*${ruby_strings%%,*}*"
then
sections="$ruby_strings"
ruby_strings=""
fi
if
[[ -z "${sections// /}" ]]
then
sections="$all_sections"
fi
rvm_is_a_shell_function || true
if
[[ -z "$ruby_strings" ]]
then
printf "%b" "\n$(__rvm_env_string):\n"
info_sections
else
for ruby_string in ${ruby_strings//,/ }
do
__rvm_become "$ruby_string"
printf "%b" "\n$(__rvm_env_string):\n"
info_sections
done
fi