Browse Source

Clean up PATH sanitization in rbenv-which

pull/360/head^2
Mislav Marohnić 11 years ago
parent
commit
3ee395f9b5
1 changed files with 12 additions and 12 deletions
  1. +12
    -12
      libexec/rbenv-which

+ 12
- 12
libexec/rbenv-which View File

@ -15,6 +15,16 @@ if [ "$1" = "--complete" ]; then
exec rbenv shims --short
fi
remove_from_path() {
local path_to_remove="$1"
local path_before
local result=":$PATH:"
while [ "$path_before" != "$result" ]; do
path_before="$result"
result="${result//:$path_to_remove:/:}"
done
echo "${result%:}"
}
RBENV_COMMAND="$1"
@ -26,18 +36,8 @@ fi
RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}"
if [ "$RBENV_VERSION" = "system" ]; then
# Remove shims from PATH. Use a loop, because Bash won't remove all ":foo:"
# in ":foo:foo:" in one go.
path=":$PATH:"
remove="${RBENV_ROOT}/shims"
while true; do
path_before="$path"
path="${path//:$remove:/:}"
if [[ "$path_before" = "$path" ]]; then
break
fi
done
RBENV_COMMAND_PATH="$(PATH=$path command -v "$RBENV_COMMAND" || true)"
PATH="$(remove_from_path "${RBENV_ROOT}/shims")"
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
else
RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}"
fi

Loading…
Cancel
Save