From d257b562e54393ad37c5f58a39fe7512cc1abcb0 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 2 Aug 2011 23:31:19 -0500 Subject: [PATCH] Add rbenv-whence to show you which versions of Ruby have a given command --- libexec/rbenv-whence | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 libexec/rbenv-whence diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence new file mode 100755 index 00000000..30613eed --- /dev/null +++ b/libexec/rbenv-whence @@ -0,0 +1,22 @@ +#!/usr/bin/env bash -e + +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" +result="$(whence "$RBENV_COMMAND")" +[ -n "$result" ] && echo "$result"