2011-08-12 09:33:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 22:34:53 +00:00
|
|
|
# Summary: Configure shell environment for rbenv
|
|
|
|
# Usage: rbenv init [SHELL]
|
|
|
|
# rbenv init - [--no-rehash] [SHELL]
|
|
|
|
|
2011-08-12 09:33:45 +00:00
|
|
|
set -e
|
2011-09-12 15:11:59 +00:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-04 04:16:28 +00:00
|
|
|
|
2011-08-04 05:45:40 +00:00
|
|
|
print=""
|
2011-12-26 01:59:24 +00:00
|
|
|
no_rehash=""
|
2012-01-17 14:50:40 +00:00
|
|
|
for args in "$@"
|
|
|
|
do
|
|
|
|
if [ "$args" = "-" ]; then
|
|
|
|
print=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$args" = "--no-rehash" ]; then
|
|
|
|
no_rehash=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
done
|
2011-12-26 01:59:24 +00:00
|
|
|
|
2011-08-04 05:45:40 +00:00
|
|
|
shell="$1"
|
2011-08-04 04:16:28 +00:00
|
|
|
if [ -z "$shell" ]; then
|
2011-08-04 05:45:40 +00:00
|
|
|
shell="$(basename "$SHELL")"
|
2011-08-04 04:16:28 +00:00
|
|
|
fi
|
|
|
|
|
2011-08-16 21:26:57 +00:00
|
|
|
resolve_link() {
|
|
|
|
$(type -p greadlink readlink | head -1) $1
|
|
|
|
}
|
|
|
|
|
2011-08-04 04:16:28 +00:00
|
|
|
abs_dirname() {
|
|
|
|
local cwd="$(pwd)"
|
|
|
|
local path="$1"
|
|
|
|
|
|
|
|
while [ -n "$path" ]; do
|
|
|
|
cd "${path%/*}"
|
|
|
|
local name="${path##*/}"
|
2011-08-16 21:26:57 +00:00
|
|
|
path="$(resolve_link "$name" || true)"
|
2011-08-04 04:16:28 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
pwd
|
|
|
|
cd "$cwd"
|
|
|
|
}
|
2011-08-04 05:45:40 +00:00
|
|
|
|
2011-08-04 04:16:28 +00:00
|
|
|
root="$(abs_dirname "$0")/.."
|
|
|
|
|
2011-08-04 05:45:40 +00:00
|
|
|
if [ -z "$print" ]; then
|
|
|
|
case "$shell" in
|
|
|
|
bash )
|
|
|
|
profile='~/.bash_profile'
|
|
|
|
;;
|
|
|
|
zsh )
|
|
|
|
profile='~/.zshrc'
|
|
|
|
;;
|
2011-12-15 20:54:38 +00:00
|
|
|
ksh )
|
|
|
|
profile='~/.profile'
|
|
|
|
;;
|
2011-08-04 05:45:40 +00:00
|
|
|
* )
|
|
|
|
profile='your profile'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
{ echo "# Load rbenv automatically by adding"
|
|
|
|
echo "# the following to ${profile}:"
|
|
|
|
echo
|
|
|
|
echo 'eval "$(rbenv init -)"'
|
|
|
|
echo
|
|
|
|
} >&2
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-09-11 16:58:57 +00:00
|
|
|
mkdir -p "${RBENV_ROOT}/"{shims,versions}
|
2011-08-04 05:48:37 +00:00
|
|
|
|
2011-09-11 16:58:57 +00:00
|
|
|
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
2011-08-04 04:16:28 +00:00
|
|
|
|
2011-08-16 05:13:12 +00:00
|
|
|
case "$shell" in
|
|
|
|
bash | zsh )
|
|
|
|
echo "source \"$root/completions/rbenv.${shell}\""
|
|
|
|
;;
|
|
|
|
esac
|
2011-08-15 06:18:04 +00:00
|
|
|
|
2011-12-26 01:59:24 +00:00
|
|
|
if [ -z "$no_rehash" ]; then
|
|
|
|
echo 'rbenv rehash 2>/dev/null'
|
|
|
|
fi
|
2011-08-23 16:34:42 +00:00
|
|
|
|
2012-08-13 17:08:39 +00:00
|
|
|
commands=(`rbenv-commands --sh`)
|
2011-08-23 16:34:42 +00:00
|
|
|
IFS="|"
|
|
|
|
cat <<EOS
|
2011-12-24 22:49:22 +00:00
|
|
|
rbenv() {
|
2012-12-13 05:01:26 +00:00
|
|
|
typeset command
|
|
|
|
command="\$1"
|
2011-09-11 00:50:12 +00:00
|
|
|
if [ "\$#" -gt 0 ]; then
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2011-09-11 00:45:36 +00:00
|
|
|
case "\$command" in
|
2011-08-23 16:34:42 +00:00
|
|
|
${commands[*]})
|
2011-09-11 00:45:36 +00:00
|
|
|
eval \`rbenv "sh-\$command" "\$@"\`;;
|
2011-08-23 16:34:42 +00:00
|
|
|
*)
|
2011-09-11 00:45:36 +00:00
|
|
|
command rbenv "\$command" "\$@";;
|
2011-09-11 00:50:12 +00:00
|
|
|
esac
|
|
|
|
}
|
2011-08-23 16:34:42 +00:00
|
|
|
EOS
|