mirror of
https://github.com/rbenv/rbenv.git
synced 2025-01-01 06:37:11 +01:00
Merge pull request #1350 from rbenv/rehash-path-to-rbenv
Have shims survive upgrades via Homebrew
This commit is contained in:
commit
0767d64344
2 changed files with 18 additions and 1 deletions
|
@ -68,6 +68,7 @@ else
|
||||||
fi
|
fi
|
||||||
export RBENV_DIR
|
export RBENV_DIR
|
||||||
|
|
||||||
|
[ -n "$RBENV_ORIG_PATH" ] || export RBENV_ORIG_PATH="$PATH"
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,22 @@ remove_prototype_shim() {
|
||||||
rm -f "$PROTOTYPE_SHIM_PATH"
|
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
|
# The prototype shim file is a script that re-execs itself, passing
|
||||||
# its filename and any arguments to `rbenv exec`. This file is
|
# its filename and any arguments to `rbenv exec`. This file is
|
||||||
# hard-linked for every executable and then removed. The linking
|
# hard-linked for every executable and then removed. The linking
|
||||||
|
@ -61,7 +77,7 @@ if [ "\$program" = "ruby" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export RBENV_ROOT="$RBENV_ROOT"
|
export RBENV_ROOT="$RBENV_ROOT"
|
||||||
exec "$(command -v rbenv)" exec "\$program" "\$@"
|
exec "$(rbenv_path)" exec "\$program" "\$@"
|
||||||
SH
|
SH
|
||||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue