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