File: rbenv-whence

package info (click to toggle)
rbenv 1.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 380 kB
  • sloc: sh: 1,597; ansic: 60; ruby: 39; makefile: 25
file content (38 lines) | stat: -rwxr-xr-x 767 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# Summary: List all Ruby versions that contain the given executable
# Usage: rbenv whence [--path] <command>

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 -r 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 --usage whence >&2
  exit 1
fi

result="$(whence "$RBENV_COMMAND")"
[ -n "$result" ] && echo "$result"