From d0779fc8fb90fb7268d0ee858086e92bcd316787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 9 Sep 2016 10:29:12 +0200 Subject: [PATCH] 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`. --- libexec/rbenv-which | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-which b/libexec/rbenv-which index c7c0301..78db1c0 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -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:/:}"