2011-08-12 09:33:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2012-12-30 04:05:04 +00:00
|
|
|
# Summary: Configure the shell environment for rbenv
|
|
|
|
# Usage: eval "$(rbenv init - [--no-rehash] [<shell>])"
|
2012-12-29 22:34:53 +00:00
|
|
|
|
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
|
|
|
|
2015-11-20 14:20:01 +00:00
|
|
|
# Provide rbenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
|
|
|
echo -
|
|
|
|
echo --no-rehash
|
|
|
|
echo bash
|
|
|
|
echo fish
|
|
|
|
echo ksh
|
|
|
|
echo zsh
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
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
|
2013-03-23 13:36:11 +00:00
|
|
|
shift
|
2012-01-17 14:50:40 +00:00
|
|
|
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
|
2015-05-10 14:03:06 +00:00
|
|
|
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
|
2014-01-02 21:36:03 +00:00
|
|
|
shell="${shell%% *}"
|
2015-12-24 12:23:01 +00:00
|
|
|
shell="${shell##-}"
|
2015-05-10 14:17:35 +00:00
|
|
|
shell="${shell:-$SHELL}"
|
|
|
|
shell="${shell##*/}"
|
2011-08-04 04:16:28 +00:00
|
|
|
fi
|
|
|
|
|
2014-01-04 15:37:20 +00:00
|
|
|
root="${0%/*}/.."
|
2011-08-04 04:16:28 +00:00
|
|
|
|
2011-08-04 05:45:40 +00:00
|
|
|
if [ -z "$print" ]; then
|
|
|
|
case "$shell" in
|
|
|
|
bash )
|
2015-10-26 14:45:52 +00:00
|
|
|
if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then
|
|
|
|
profile='~/.bashrc'
|
|
|
|
else
|
|
|
|
profile='~/.bash_profile'
|
|
|
|
fi
|
2011-08-04 05:45:40 +00:00
|
|
|
;;
|
|
|
|
zsh )
|
|
|
|
profile='~/.zshrc'
|
|
|
|
;;
|
2011-12-15 20:54:38 +00:00
|
|
|
ksh )
|
|
|
|
profile='~/.profile'
|
|
|
|
;;
|
2013-08-15 14:01:13 +00:00
|
|
|
fish )
|
|
|
|
profile='~/.config/fish/config.fish'
|
|
|
|
;;
|
2011-08-04 05:45:40 +00:00
|
|
|
* )
|
|
|
|
profile='your profile'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-09-12 22:27:32 +00:00
|
|
|
{ echo "# Load rbenv automatically by appending"
|
2011-08-04 05:45:40 +00:00
|
|
|
echo "# the following to ${profile}:"
|
|
|
|
echo
|
2013-09-28 13:04:24 +00:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
2016-02-20 15:27:39 +00:00
|
|
|
echo 'status --is-interactive; and source (rbenv init -|psub)'
|
2013-09-28 13:04:24 +00:00
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo 'eval "$(rbenv init -)"'
|
|
|
|
;;
|
|
|
|
esac
|
2011-08-04 05:45:40 +00:00
|
|
|
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
|
|
|
|
2013-09-28 16:43:39 +00:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
2014-10-14 23:36:20 +00:00
|
|
|
echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH"
|
2013-09-28 16:43:39 +00:00
|
|
|
echo "setenv RBENV_SHELL $shell"
|
|
|
|
;;
|
|
|
|
* )
|
2014-10-14 23:36:20 +00:00
|
|
|
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
2013-09-28 16:43:39 +00:00
|
|
|
echo "export RBENV_SHELL=$shell"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-09-09 07:53:29 +00:00
|
|
|
completion="${root}/completions/rbenv.${shell}"
|
2013-10-03 14:12:24 +00:00
|
|
|
if [ -r "$completion" ]; then
|
2016-02-20 15:27:39 +00:00
|
|
|
echo "source '$completion'"
|
2013-10-03 14:12:24 +00:00
|
|
|
fi
|
2011-08-15 06:18:04 +00:00
|
|
|
|
2011-12-26 01:59:24 +00:00
|
|
|
if [ -z "$no_rehash" ]; then
|
2014-11-29 05:16:14 +00:00
|
|
|
echo 'command rbenv rehash 2>/dev/null'
|
2011-12-26 01:59:24 +00:00
|
|
|
fi
|
2011-08-23 16:34:42 +00:00
|
|
|
|
2012-08-13 17:08:39 +00:00
|
|
|
commands=(`rbenv-commands --sh`)
|
2013-08-15 14:01:13 +00:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
|
|
|
cat <<EOS
|
|
|
|
function rbenv
|
|
|
|
set command \$argv[1]
|
2013-09-28 13:04:24 +00:00
|
|
|
set -e argv[1]
|
2013-08-15 14:01:13 +00:00
|
|
|
|
|
|
|
switch "\$command"
|
|
|
|
case ${commands[*]}
|
2016-02-20 15:27:39 +00:00
|
|
|
source (rbenv "sh-\$command" \$argv|psub)
|
2013-08-15 14:01:13 +00:00
|
|
|
case '*'
|
|
|
|
command rbenv "\$command" \$argv
|
|
|
|
end
|
|
|
|
end
|
2013-09-28 13:58:13 +00:00
|
|
|
EOS
|
|
|
|
;;
|
|
|
|
ksh )
|
|
|
|
cat <<EOS
|
|
|
|
function rbenv {
|
|
|
|
typeset command
|
2013-08-15 14:01:13 +00:00
|
|
|
EOS
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
cat <<EOS
|
2011-12-24 22:49:22 +00:00
|
|
|
rbenv() {
|
2013-09-28 13:58:13 +00:00
|
|
|
local command
|
|
|
|
EOS
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2014-06-02 17:36:49 +00:00
|
|
|
if [ "$shell" != "fish" ]; then
|
2013-09-28 13:58:13 +00:00
|
|
|
IFS="|"
|
|
|
|
cat <<EOS
|
2012-12-13 05:01:26 +00:00
|
|
|
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[*]})
|
2015-10-11 23:31:57 +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
|
2014-06-02 17:36:49 +00:00
|
|
|
fi
|