From 6426f852d091f1794701dc1b99faa86c58d2df30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 25 Sep 2022 22:32:46 +0200 Subject: [PATCH] Use absolute path in `rbenv init` instructions if needed --- libexec/rbenv-init | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index cabea21e..00e2274a 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -45,6 +45,11 @@ root="${BASH_SOURCE:-$0}" root="${root%/*}" root="${root%/*}" +rbenv_in_path=true +if [ -n "$RBENV_ORIG_PATH" ]; then + PATH="$RBENV_ORIG_PATH" command -v rbenv >/dev/null || rbenv_in_path="" +fi + if [ -z "$print" ]; then case "$shell" in bash ) @@ -68,18 +73,27 @@ if [ -z "$print" ]; then ;; esac - { echo "# Load rbenv automatically by appending" - echo "# the following to ${profile}:" + 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." echo + [ -t 2 ] && printf '\e[33;1m' case "$shell" in fish ) - echo 'status --is-interactive; and rbenv init - fish | source' + printf 'status --is-interactive; and %s init - fish | source' "$rbenv_command" ;; * ) # shellcheck disable=SC2016 - printf 'eval "$(rbenv init - %s)"\n' "$shell" + printf 'eval "$(%s init - %s)"' "$rbenv_command" "$shell" ;; esac + [ -t 2 ] && printf '\e[m' + echo echo } >&2 @@ -88,11 +102,6 @@ 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 ) [ -n "$rbenv_in_path" ] || printf "set -gx PATH '%s/bin' \$PATH\n" "$root"