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