pyenv/libexec/rbenv-whence
Mislav Marohnić b8715bfee6 foundation for a help system where each command holds its own docs
Docs are comprised from "Usage", "Summary" and "Help" sections, where
"Help" can span multiple commented lines. If it is missing, "Summary" is
shown in its place.

References #204, references #206
2012-12-13 05:48:28 +01:00

37 lines
762 B
Bash
Executable file

#!/usr/bin/env bash
# Usage: rbenv whence [--path] COMMAND
# Summary: List all Ruby versions with the given command installed
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo --path
exec rbenv shims --short
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
rbenv-help whence | head -1 >&2
exit 1
fi
result="$(whence "$RBENV_COMMAND")"
[ -n "$result" ] && echo "$result"