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.

88 lines
1.6 KiB

13 years ago
13 years ago
13 years ago
11 years ago
13 years ago
  1. #!/usr/bin/env bash
  2. set -e
  3. export -n CDPATH
  4. if [ "$1" = "--debug" ]; then
  5. export RBENV_DEBUG=1
  6. shift
  7. fi
  8. if [ -n "$RBENV_DEBUG" ]; then
  9. export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
  10. set -x
  11. fi
  12. resolve_link() {
  13. $(type -p greadlink readlink | head -1) "$1"
  14. }
  15. abs_dirname() {
  16. local cwd="$(pwd)"
  17. local path="$1"
  18. while [ -n "$path" ]; do
  19. cd "${path%/*}"
  20. local name="${path##*/}"
  21. path="$(resolve_link "$name" || true)"
  22. done
  23. pwd
  24. cd "$cwd"
  25. }
  26. if [ -z "${RBENV_ROOT}" ]; then
  27. RBENV_ROOT="${HOME}/.rbenv"
  28. else
  29. RBENV_ROOT="${RBENV_ROOT%/}"
  30. fi
  31. export RBENV_ROOT
  32. if [ -z "${RBENV_DIR}" ]; then
  33. RBENV_DIR="$(pwd)"
  34. else
  35. cd "$RBENV_DIR" 2>/dev/null || {
  36. echo "rbenv: cannot change working directory to \`$RBENV_DIR'"
  37. exit 1
  38. } >&2
  39. RBENV_DIR="$(pwd)"
  40. cd "$OLDPWD"
  41. fi
  42. export RBENV_DIR
  43. shopt -s nullglob
  44. bin_path="$(abs_dirname "$0")"
  45. for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
  46. bin_path="${bin_path}:${plugin_bin}"
  47. done
  48. export PATH="${bin_path}:${PATH}"
  49. hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
  50. for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
  51. hook_path="${hook_path}:${plugin_hook}"
  52. done
  53. export RBENV_HOOK_PATH="$hook_path"
  54. shopt -u nullglob
  55. command="$1"
  56. case "$command" in
  57. "" | "-h" | "--help" )
  58. echo -e "$(rbenv---version)\n$(rbenv-help)" >&2
  59. ;;
  60. "-v" )
  61. exec rbenv---version
  62. ;;
  63. * )
  64. command_path="$(command -v "rbenv-$command" || true)"
  65. if [ -z "$command_path" ]; then
  66. echo "rbenv: no such command \`$command'" >&2
  67. exit 1
  68. fi
  69. shift 1
  70. exec "$command_path" "$@"
  71. ;;
  72. esac