Expand literal tilde in PATH

The literal tilde in a PATH entry (e.g. `~/.rbenv/shims`) doesn't seem
to be supported by system `which` utility, but *does* seem to be
supported by `command -v` (used in `rbenv-which`) and `type -p`.

Therefore, we must strip away `~/.rbenv/shims` from PATH when looking up
executables for system Ruby, lest we risk infinite loop. We do so by
substituting any occurence of `~` in PATH with the value of `HOME`.
This commit is contained in:
Mislav Marohnić 2016-09-09 10:29:12 +02:00
parent 0c7224af95
commit d0779fc8fb

View file

@ -18,7 +18,7 @@ fi
remove_from_path() {
local path_to_remove="$1"
local path_before
local result=":$PATH:"
local result=":${PATH//\~/$HOME}:"
while [ "$path_before" != "$result" ]; do
path_before="$result"
result="${result//:$path_to_remove:/:}"