2011-08-12 09:33:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 22:34:53 +00:00
|
|
|
# Summary: List all Ruby versions that contain the given executable
|
2012-12-30 22:00:53 +00:00
|
|
|
# Usage: rbenv whence [--path] <command>
|
2012-12-29 18:06:20 +00:00
|
|
|
|
2011-08-12 09:33:45 +00:00
|
|
|
set -e
|
2011-09-12 15:11:59 +00:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-03 04:31:19 +00:00
|
|
|
|
2011-09-13 17:59:59 +00:00
|
|
|
# Provide rbenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
|
|
|
echo --path
|
2014-10-14 23:24:45 +00:00
|
|
|
exec rbenv-shims --short
|
2011-09-13 17:59:59 +00:00
|
|
|
fi
|
|
|
|
|
2011-08-03 04:31:19 +00:00
|
|
|
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"
|
2011-08-03 05:06:23 +00:00
|
|
|
if [ -z "$RBENV_COMMAND" ]; then
|
2012-12-29 18:12:47 +00:00
|
|
|
rbenv-help --usage whence >&2
|
2011-08-03 05:06:23 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-08-03 04:31:19 +00:00
|
|
|
result="$(whence "$RBENV_COMMAND")"
|
|
|
|
[ -n "$result" ] && echo "$result"
|