bundler-exec.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # Automatically run Ruby scripts with "bundle exec" (but only when appropriate).
  3. # http://effectif.com/ruby/automating-bundle-exec
  4. # Github: https://github.com/gma/bundler-exec
  5. ## Functions
  6. bundler-installed()
  7. {
  8. which bundle > /dev/null 2>&1
  9. }
  10. within-bundled-project()
  11. {
  12. local dir="$(pwd)"
  13. while [ "$dir" != "/" ]; do
  14. if [ -f "$dir/Gemfile" ]; then
  15. return 0
  16. fi
  17. dir="$(dirname $dir)"
  18. done
  19. return 1
  20. }
  21. run-with-bundler()
  22. {
  23. if bundler-installed && within-bundled-project; then
  24. bundle exec "$@"
  25. else
  26. "$@"
  27. fi
  28. }
  29. define-bundler-aliases()
  30. {
  31. # Allow zsh to iterate over list of words
  32. [ -n "$ZSH_VERSION" ] && setopt localoptions shwordsplit
  33. local command
  34. for command in $BUNDLED_COMMANDS; do
  35. if [[ $command != "bundle" && $command != "gem" ]]; then
  36. alias $command="run-with-bundler $command"
  37. fi
  38. done
  39. }
  40. ## Main program
  41. BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
  42. cap
  43. capify
  44. chef
  45. chefspec
  46. chef-apply
  47. chef-client
  48. chef-shell
  49. chef-solo
  50. cucumber
  51. foodcritic
  52. guard
  53. haml
  54. html2haml
  55. jasmine
  56. jekyll
  57. kitchen
  58. knife
  59. middleman
  60. pry
  61. rackup
  62. rake
  63. rake2thor
  64. rspec
  65. ruby
  66. sass
  67. sass-convert
  68. serve
  69. shotgun
  70. sidekiq
  71. spec
  72. spork
  73. strainer
  74. thin
  75. thor
  76. tilt
  77. tt
  78. turn
  79. unicorn
  80. unicorn_rails
  81. wagon
  82. }"
  83. define-bundler-aliases
  84. unset -f define-bundler-aliases