Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have shims survive upgrades via Homebrew #1350

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions libexec/rbenv
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ else
fi
export RBENV_DIR

[ -n "$RBENV_ORIG_PATH" ] || export RBENV_ORIG_PATH="$PATH"

shopt -s nullglob

Expand Down
18 changes: 17 additions & 1 deletion libexec/rbenv-rehash
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ remove_prototype_shim() {
rm -f "$PROTOTYPE_SHIM_PATH"
}

# Locates rbenv as found in the user's PATH. Otherwise, returns an
# absolute path to the rbenv executable itself.
rbenv_path() {
local found
found="$(PATH="$RBENV_ORIG_PATH" command -v rbenv)"
if [[ $found == /* ]]; then
echo "$found"
elif [[ -n "$found" ]]; then
echo "$PWD/${found#./}"
else
# Assume rbenv isn't in PATH.
local here="${BASH_SOURCE%/*}"
echo "${here%/*}/bin/rbenv"
fi
}

# The prototype shim file is a script that re-execs itself, passing
# its filename and any arguments to `rbenv exec`. This file is
# hard-linked for every executable and then removed. The linking
Expand Down Expand Up @@ -61,7 +77,7 @@ if [ "\$program" = "ruby" ]; then
fi

export RBENV_ROOT="$RBENV_ROOT"
exec "$(command -v rbenv)" exec "\$program" "\$@"
exec "$(rbenv_path)" exec "\$program" "\$@"
SH
chmod +x "$PROTOTYPE_SHIM_PATH"
}
Expand Down