You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
769 B

  1. #!/usr/bin/env bash
  2. # Summary: List all Python versions that contain the given executable
  3. # Usage: pyenv whence [--path] <command>
  4. set -e
  5. [ -n "$PYENV_DEBUG" ] && set -x
  6. # Provide pyenv completions
  7. if [ "$1" = "--complete" ]; then
  8. echo --path
  9. exec pyenv-shims --short
  10. fi
  11. if [ "$1" = "--path" ]; then
  12. print_paths="1"
  13. shift
  14. else
  15. print_paths=""
  16. fi
  17. whence() {
  18. local command="$1"
  19. pyenv-versions --bare | while read -r version; do
  20. path="$(pyenv-prefix "$version")/bin/${command}"
  21. if [ -x "$path" ]; then
  22. [ "$print_paths" ] && echo "$path" || echo "$version"
  23. fi
  24. done
  25. }
  26. PYENV_COMMAND="$1"
  27. if [ -z "$PYENV_COMMAND" ]; then
  28. pyenv-help --usage whence >&2
  29. exit 1
  30. fi
  31. result="$(whence "$PYENV_COMMAND")"
  32. [ -n "$result" ] && echo "$result"