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.

54 line
971 B

11 年之前
  1. #!/usr/bin/env bash
  2. # Summary: List hook scripts for a given rbenv command
  3. # Usage: rbenv hooks <command>
  4. set -e
  5. [ -n "$RBENV_DEBUG" ] && set -x
  6. # Provide rbenv completions
  7. if [ "$1" = "--complete" ]; then
  8. echo exec
  9. echo rehash
  10. echo which
  11. exit
  12. fi
  13. RBENV_COMMAND="$1"
  14. if [ -z "$RBENV_COMMAND" ]; then
  15. rbenv-help --usage hooks >&2
  16. exit 1
  17. fi
  18. READLINK=$(type -p greadlink readlink | head -1)
  19. if [ -z "$READLINK" ]; then
  20. echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
  21. exit 1
  22. fi
  23. resolve_link() {
  24. $READLINK "$1"
  25. }
  26. realpath() {
  27. local cwd="$(pwd)"
  28. local path="$1"
  29. while [ -n "$path" ]; do
  30. cd "${path%/*}"
  31. local name="${path##*/}"
  32. path="$(resolve_link "$name" || true)"
  33. done
  34. echo "$(pwd)/$name"
  35. cd "$cwd"
  36. }
  37. IFS=: hook_paths=($RBENV_HOOK_PATH)
  38. shopt -s nullglob
  39. for path in "${hook_paths[@]}"; do
  40. for script in "$path/$RBENV_COMMAND"/*.bash; do
  41. echo $(realpath $script)
  42. done
  43. done
  44. shopt -u nullglob