pyenv/libexec/rbenv-whence

39 lines
764 B
Text
Raw Normal View History

#!/usr/bin/env bash
# Summary: List all Ruby versions that contain the given executable
2012-12-30 22:00:53 +00:00
# Usage: rbenv whence [--path] <command>
set -e
[ -n "$RBENV_DEBUG" ] && set -x
2011-09-13 17:59:59 +00:00
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo --path
exec rbenv-shims --short
2011-09-13 17:59:59 +00:00
fi
if [ "$1" = "--path" ]; then
print_paths="1"
shift
else
print_paths=""
fi
whence() {
local command="$1"
rbenv-versions --bare | while read version; do
path="$(rbenv-prefix "$version")/bin/${command}"
if [ -x "$path" ]; then
[ "$print_paths" ] && echo "$path" || echo "$version"
fi
done
}
RBENV_COMMAND="$1"
if [ -z "$RBENV_COMMAND" ]; then
2012-12-29 18:12:47 +00:00
rbenv-help --usage whence >&2
exit 1
fi
result="$(whence "$RBENV_COMMAND")"
[ -n "$result" ] && echo "$result"