2011-08-12 11:33:45 +02:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 22:05:04 -06: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 10:11:59 -05:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-03 23:16:28 -05: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 00:45:40 -05:00
|
|
|
print=""
|
2011-12-25 20:59:24 -05:00
|
|
|
no_rehash=""
|
2012-01-17 08:50:40 -06:00
|
|
|
for args in "$@"
|
|
|
|
|
do
|
|
|
|
|
if [ "$args" = "-" ]; then
|
|
|
|
|
print=1
|
2013-03-23 22:36:11 +09:00
|
|
|
shift
|
2012-01-17 08:50:40 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$args" = "--no-rehash" ]; then
|
|
|
|
|
no_rehash=1
|
|
|
|
|
shift
|
|
|
|
|
fi
|
|
|
|
|
done
|
2011-12-25 20:59:24 -05:00
|
|
|
|
2011-08-04 00:45:40 -05:00
|
|
|
shell="$1"
|
2011-08-03 23:16:28 -05:00
|
|
|
if [ -z "$shell" ]; then
|
2015-05-10 16:03:06 +02:00
|
|
|
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
|
2014-01-02 22:36:03 +01:00
|
|
|
shell="${shell%% *}"
|
2015-12-24 13:23:01 +01:00
|
|
|
shell="${shell##-}"
|
2015-05-10 16:17:35 +02:00
|
|
|
shell="${shell:-$SHELL}"
|
|
|
|
|
shell="${shell##*/}"
|
2021-03-01 07:49:47 +02:00
|
|
|
shell="${shell%%-*}"
|
2011-08-03 23:16:28 -05:00
|
|
|
fi
|
|
|
|
|
|
2022-09-24 23:59:13 +02:00
|
|
|
root="${BASH_SOURCE:-$0}"
|
|
|
|
|
root="${root%/*}"
|
|
|
|
|
root="${root%/*}"
|
2011-08-03 23:16:28 -05:00
|
|
|
|
2022-09-25 22:32:46 +02:00
|
|
|
rbenv_in_path=true
|
|
|
|
|
if [ -n "$RBENV_ORIG_PATH" ]; then
|
2022-10-07 16:34:38 +02:00
|
|
|
PATH="$RBENV_ORIG_PATH" type -P rbenv >/dev/null || rbenv_in_path=""
|
2022-09-25 22:32:46 +02:00
|
|
|
fi
|
|
|
|
|
|
2011-08-04 00:45:40 -05: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 00:45:40 -05:00
|
|
|
;;
|
|
|
|
|
zsh )
|
|
|
|
|
profile='~/.zshrc'
|
|
|
|
|
;;
|
2023-05-13 12:56:22 -04:00
|
|
|
ksh | ksh93 | mksh )
|
|
|
|
|
# There are two implementations of Korn shell: AT&T (ksh93) and Mir (mksh).
|
|
|
|
|
# Systems may have them installed under those names, or as ksh, so those
|
|
|
|
|
# are recognized here. The obsolete ksh88 (subsumed by ksh93) and pdksh
|
|
|
|
|
# (subsumed by mksh) are not included, since they are unlikely to still
|
|
|
|
|
# be in use as interactive shells anywhere.
|
2011-12-15 14:54:38 -06:00
|
|
|
profile='~/.profile'
|
|
|
|
|
;;
|
2013-08-15 23:01:13 +09:00
|
|
|
fish )
|
|
|
|
|
profile='~/.config/fish/config.fish'
|
|
|
|
|
;;
|
2011-08-04 00:45:40 -05:00
|
|
|
* )
|
|
|
|
|
profile='your profile'
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2022-09-25 22:32:46 +02:00
|
|
|
rbenv_command=rbenv
|
|
|
|
|
if [ -z "$rbenv_in_path" ]; then
|
|
|
|
|
rbenv_command="$root/bin/rbenv"
|
|
|
|
|
rbenv_command="${rbenv_command/$HOME\//~/}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
{ echo "# Please add the following line to your \`${profile}' file,"
|
|
|
|
|
echo "# then restart your terminal."
|
2011-08-04 00:45:40 -05:00
|
|
|
echo
|
2022-09-25 22:32:46 +02:00
|
|
|
[ -t 2 ] && printf '\e[33;1m'
|
2013-09-28 15:04:24 +02:00
|
|
|
case "$shell" in
|
|
|
|
|
fish )
|
2022-09-25 22:32:46 +02:00
|
|
|
printf 'status --is-interactive; and %s init - fish | source' "$rbenv_command"
|
2013-09-28 15:04:24 +02:00
|
|
|
;;
|
|
|
|
|
* )
|
2022-09-24 23:59:13 +02:00
|
|
|
# shellcheck disable=SC2016
|
2022-09-25 22:32:46 +02:00
|
|
|
printf 'eval "$(%s init - %s)"' "$rbenv_command" "$shell"
|
2013-09-28 15:04:24 +02:00
|
|
|
;;
|
|
|
|
|
esac
|
2022-09-25 22:32:46 +02:00
|
|
|
[ -t 2 ] && printf '\e[m'
|
|
|
|
|
echo
|
2011-08-04 00:45:40 -05:00
|
|
|
echo
|
|
|
|
|
} >&2
|
|
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2011-09-11 11:58:57 -05:00
|
|
|
mkdir -p "${RBENV_ROOT}/"{shims,versions}
|
2011-08-04 00:48:37 -05:00
|
|
|
|
2013-09-28 18:43:39 +02:00
|
|
|
case "$shell" in
|
|
|
|
|
fish )
|
2022-09-24 23:59:13 +02:00
|
|
|
[ -n "$rbenv_in_path" ] || printf "set -gx PATH '%s/bin' \$PATH\n" "$root"
|
|
|
|
|
printf "set -gx PATH '%s/shims' \$PATH\n" "$RBENV_ROOT"
|
|
|
|
|
printf 'set -gx RBENV_SHELL %s\n' "$shell"
|
2013-09-28 18:43:39 +02:00
|
|
|
;;
|
|
|
|
|
* )
|
2022-09-24 23:59:13 +02:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
|
[ -n "$rbenv_in_path" ] || printf 'export PATH="%s/bin:${PATH}"\n' "$root"
|
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
|
printf 'export PATH="%s/shims:${PATH}"\n' "$RBENV_ROOT"
|
|
|
|
|
printf 'export RBENV_SHELL=%s\n' "$shell"
|
2020-01-28 17:47:59 +01:00
|
|
|
|
|
|
|
|
completion="${root}/completions/rbenv.${shell}"
|
|
|
|
|
if [ -r "$completion" ]; then
|
2022-09-24 23:59:13 +02:00
|
|
|
printf "source '%s'\n" "$completion"
|
2020-01-28 17:47:59 +01:00
|
|
|
fi
|
2013-09-28 18:43:39 +02:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2011-12-25 20:59:24 -05:00
|
|
|
if [ -z "$no_rehash" ]; then
|
2014-11-28 21:16:14 -08:00
|
|
|
echo 'command rbenv rehash 2>/dev/null'
|
2011-12-25 20:59:24 -05:00
|
|
|
fi
|
2011-08-23 11:34:42 -05:00
|
|
|
|
2022-10-09 14:48:13 +02:00
|
|
|
IFS=$'\n' read -d '' -r -a commands <<<"$(rbenv-commands --sh)" || true
|
|
|
|
|
|
2013-08-15 23:01:13 +09: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 23:01:13 +09:00
|
|
|
|
|
|
|
|
switch "\$command"
|
|
|
|
|
case ${commands[*]}
|
2020-02-17 21:32:12 +01:00
|
|
|
rbenv "sh-\$command" \$argv|source
|
2013-08-15 23:01:13 +09:00
|
|
|
case '*'
|
|
|
|
|
command rbenv "\$command" \$argv
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-09-28 15:58:13 +02:00
|
|
|
EOS
|
|
|
|
|
;;
|
2023-05-13 12:56:22 -04:00
|
|
|
ksh | ksh93 | mksh )
|
2013-09-28 15:58:13 +02:00
|
|
|
cat <<EOS
|
|
|
|
|
function rbenv {
|
|
|
|
|
typeset command
|
2013-08-15 23:01:13 +09:00
|
|
|
EOS
|
|
|
|
|
;;
|
|
|
|
|
* )
|
|
|
|
|
cat <<EOS
|
2011-12-24 17:49:22 -05:00
|
|
|
rbenv() {
|
2013-09-28 15:58:13 +02:00
|
|
|
local command
|
|
|
|
|
EOS
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2014-06-03 00:36:49 +07:00
|
|
|
if [ "$shell" != "fish" ]; then
|
2013-09-28 15:58:13 +02:00
|
|
|
IFS="|"
|
|
|
|
|
cat <<EOS
|
2017-01-01 22:06:39 -08:00
|
|
|
command="\${1:-}"
|
2011-09-10 19:50:12 -05:00
|
|
|
if [ "\$#" -gt 0 ]; then
|
|
|
|
|
shift
|
|
|
|
|
fi
|
|
|
|
|
|
2011-09-10 19:45:36 -05:00
|
|
|
case "\$command" in
|
2011-08-23 11:34:42 -05:00
|
|
|
${commands[*]})
|
2015-10-12 01:31:57 +02:00
|
|
|
eval "\$(rbenv "sh-\$command" "\$@")";;
|
2011-08-23 11:34:42 -05:00
|
|
|
*)
|
2011-09-10 19:45:36 -05:00
|
|
|
command rbenv "\$command" "\$@";;
|
2011-09-10 19:50:12 -05:00
|
|
|
esac
|
|
|
|
|
}
|
2011-08-23 11:34:42 -05:00
|
|
|
EOS
|
2014-06-03 00:36:49 +07:00
|
|
|
fi
|