-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenv.sh
executable file
·69 lines (62 loc) · 1.89 KB
/
renv.sh
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
#!/usr/bin/env sh
# shellcheck disable=SC2039
renv() {
case "$1" in
status | s)
[ -n "${GEM_HOME:-}" ] && echo "GEM_HOME='$GEM_HOME'"
[ -n "${GEM_PATH:-}" ] && echo "GEM_PATH='$GEM_PATH'"
echo "PATH='$PATH'" && return
;;
reset | r)
if [ -z "${RENV_ORIG_PATH:-}" ]; then
echo ">>>> renv not set. Try: 'renv'"
return 3
fi
if [ -n "${RENV_ORIG_GEM_HOME:-}" ]; then
GEM_HOME=$RENV_ORIG_GEM_HOME
else
unset GEM_HOME
fi
if [ -n "${RENV_ORIG_GEM_PATH:-}" ]; then
GEM_PATH=$RENV_ORIG_GEM_PATH
else
unset GEM_PATH
fi
if [ -n "${RENV_ORIG_PATH:-}" ]; then
PATH=$RENV_ORIG_PATH
fi
unset RENV_ORIG_GEM_HOME RENV_ORIG_GEM_PATH RENV_ORIG_PATH
echo "---> renv is reset, GEM_HOME='${GEM_HOME:-"<unset>"}'."
;;
set | "")
if [ -n "${RENV_ORIG_PATH:-}" ]; then
echo ">>>> renv is active, GEM_HOME='${GEM_HOME:-}'. Try: 'renv reset'"
return 9
fi
if ! command -v ruby >/dev/null; then
echo ">>>> 'ruby' program not found in PATH='${PATH:-}', aborting"
return 10
fi
eval "$(
ruby -rrubygems - <<-'EOF'
puts "local ruby_engine=#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'}"
puts "local ruby_version=#{RUBY_VERSION}"
puts "local gem_path='#{Gem.path.join(':')}'"
EOF
)"
# shellcheck disable=SC2154
local gem_dir="$PWD/.gem/$ruby_engine/$ruby_version"
export RENV_ORIG_PATH="$PATH"
export RENV_ORIG_GEM_HOME="$GEM_HOME"
export RENV_ORIG_GEM_PATH="$GEM_PATH"
export PATH="$gem_dir/bin:$PATH"
export GEM_HOME="$gem_dir"
# shellcheck disable=SC2154
export GEM_PATH="$gem_dir:$gem_path"
echo "---> renv is set, GEM_HOME={$GEM_HOME}"
;;
help | h | --help | -h | *)
echo "usage: renv [help|reset|set|status]"
;;
esac
}