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