after_cd_bundler 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env bash
  2. \. "${rvm_path}/scripts/functions/hooks/binstubs"
  3. function add_binstubs_to_path()
  4. {
  5. remove_binstubs_from_path "${2:-$1}"
  6. export PATH="$1:$PATH"
  7. export LAST_BUNDLER_BIN_PATH="$1"
  8. }
  9. BUNDLER_BIN_PATH=""
  10. # see BUNDLE_BIN is set in the current directories .bundle/config
  11. if
  12. [[ -f .bundle/config && -r .bundle/config ]] &&
  13. BUNDLER_BIN_PATH="$(\awk -F": " '$1=="BUNDLE_BIN"{print $2}' .bundle/config)" &&
  14. [[ -n "$BUNDLER_BIN_PATH" ]]
  15. then
  16. case "$BUNDLER_BIN_PATH" in
  17. (/*)
  18. true # it's all fine
  19. ;;
  20. (\~*)
  21. BUNDLER_BIN_PATH="${BUNDLER_BIN_PATH/\~/$HOME}"
  22. ;;
  23. (*HOME*)
  24. eval BUNDLER_BIN_PATH=\"${BUNDLER_BIN_PATH}\"
  25. ;;
  26. (*)
  27. BUNDLER_BIN_PATH="$PWD/${BUNDLER_BIN_PATH}"
  28. ;;
  29. esac
  30. if
  31. [[ ":$PATH:" =~ ":$BUNDLER_BIN_PATH:" ]]
  32. then
  33. echo "The bundler binstubs directory is already on path."
  34. add_binstubs_to_path "${BUNDLER_BIN_PATH}"
  35. else
  36. case "${BUNDLER_BIN_PATH}" in
  37. (${PWD}*)
  38. if
  39. __rvm_ask_for \
  40. "The bundler binstubs directory is in the current directory, which may be unsafe.
  41. Consider using rubygems-bundler instead => https://github.com/rvm/rubygems-bundler
  42. Remove the BUNDLE_BIN line from .bundle/config to disable this prompt.
  43. Are you sure you want to add the bundler binstubs directory to the path?" \
  44. 'Yes'
  45. then
  46. add_binstubs_to_path "${BUNDLER_BIN_PATH}" "${LAST_BUNDLER_BIN_PATH}"
  47. fi
  48. ;;
  49. (*)
  50. add_binstubs_to_path "${BUNDLER_BIN_PATH}" "${LAST_BUNDLER_BIN_PATH}"
  51. ;;
  52. esac
  53. fi
  54. else
  55. # There is no BUNDLE_BIN setting
  56. remove_binstubs_from_path "${LAST_BUNDLER_BIN_PATH}"
  57. fi