mirror of
https://github.com/rbenv/rbenv.git
synced 2024-12-29 13:15:42 +01:00
Init script automatically adds rbenv to PATH if necessary (#1432)
This commit is contained in:
parent
117a381575
commit
9572edf4bb
2 changed files with 19 additions and 7 deletions
|
@ -41,7 +41,9 @@ if [ -z "$shell" ]; then
|
|||
shell="${shell%%-*}"
|
||||
fi
|
||||
|
||||
root="${0%/*}/.."
|
||||
root="${BASH_SOURCE:-$0}"
|
||||
root="${root%/*}"
|
||||
root="${root%/*}"
|
||||
|
||||
if [ -z "$print" ]; then
|
||||
case "$shell" in
|
||||
|
@ -74,6 +76,7 @@ if [ -z "$print" ]; then
|
|||
echo 'status --is-interactive; and rbenv init - fish | source'
|
||||
;;
|
||||
* )
|
||||
# shellcheck disable=SC2016
|
||||
printf 'eval "$(rbenv init - %s)"\n' "$shell"
|
||||
;;
|
||||
esac
|
||||
|
@ -85,18 +88,27 @@ fi
|
|||
|
||||
mkdir -p "${RBENV_ROOT}/"{shims,versions}
|
||||
|
||||
rbenv_in_path=true
|
||||
if [ -n "$RBENV_ORIG_PATH" ]; then
|
||||
PATH="$RBENV_ORIG_PATH" command -v rbenv >/dev/null || rbenv_in_path=""
|
||||
fi
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
|
||||
echo "set -gx RBENV_SHELL $shell"
|
||||
[ -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"
|
||||
;;
|
||||
* )
|
||||
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
||||
echo "export RBENV_SHELL=$shell"
|
||||
# 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"
|
||||
|
||||
completion="${root}/completions/rbenv.${shell}"
|
||||
if [ -r "$completion" ]; then
|
||||
echo "source '$completion'"
|
||||
printf "source '%s'\n" "$completion"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -21,7 +21,7 @@ load test_helper
|
|||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||
run rbenv-init - bash
|
||||
assert_success
|
||||
assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'"
|
||||
assert_line "source '${root}/test/../completions/rbenv.bash'"
|
||||
}
|
||||
|
||||
@test "detect parent shell" {
|
||||
|
|
Loading…
Reference in a new issue