diff --git a/libexec/rbenv-prefix b/libexec/rbenv-prefix index f2823b31..9d17ee42 100755 --- a/libexec/rbenv-prefix +++ b/libexec/rbenv-prefix @@ -6,6 +6,12 @@ elif [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version)" fi +if [ "$RBENV_VERSION" = "system" ]; then + RUBY_PATH="$(rbenv-which ruby)" + echo "${RUBY_PATH%/*}" + exit +fi + RBENV_PREFIX_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" if [ ! -d "$RBENV_PREFIX_PATH" ]; then echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 diff --git a/libexec/rbenv-version b/libexec/rbenv-version index 01c1afdf..2c9cae13 100755 --- a/libexec/rbenv-version +++ b/libexec/rbenv-version @@ -36,6 +36,11 @@ if [ -z "$RBENV_VERSION" ]; then fi fi +if [ "$RBENV_VERSION" = "system" ]; then + echo "$RBENV_VERSION" + exit +fi + RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}" if [ -d "$RBENV_VERSION_PATH" ]; then diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 7f308e2d..42dde049 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -1,8 +1,35 @@ #!/usr/bin/env bash -e +expand_path() { + local cwd="$(pwd)" + cd "$1" + pwd + cd "$cwd" +} + +remove_from_path() { + local path_to_remove="$(expand_path "$1")" + local result="" + + for path in ${PATH//:/$'\n'}; do + path="$(expand_path "$path" || true)" + if [ "$path" != "$path_to_remove" ]; then + result="${result}${path}:" + fi + done + + echo "${result%:}" +} + RBENV_VERSION="$(rbenv-version)" RBENV_COMMAND="$1" -RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" + +if [ "$RBENV_VERSION" = "system" ]; then + PATH="$(remove_from_path "${HOME}/.rbenv/shims")" + RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")" +else + RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" +fi if [ -x "$RBENV_COMMAND_PATH" ]; then echo "$RBENV_COMMAND_PATH"