bundler-exec.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 [ "$(dirname $dir)" != "/" ]; do
  14. [ -f "$dir/Gemfile" ] && return
  15. dir="$(dirname $dir)"
  16. done
  17. false
  18. }
  19. run-with-bundler()
  20. {
  21. if bundler-installed && within-bundled-project; then
  22. bundle exec "$@"
  23. else
  24. "$@"
  25. fi
  26. }
  27. ## Main program
  28. BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
  29. berks
  30. cap
  31. capify
  32. chefspec
  33. chef-apply
  34. chef-client
  35. chef-shell
  36. chef-solo
  37. cucumber
  38. foodcritic
  39. foreman
  40. guard
  41. haml
  42. html2haml
  43. jasmine
  44. kitchen
  45. knife
  46. middleman
  47. pry
  48. rackup
  49. rake
  50. rake2thor
  51. rspec
  52. ruby
  53. sass
  54. sass-convert
  55. serve
  56. shotgun
  57. spec
  58. spork
  59. strainer
  60. thin
  61. thor
  62. tilt
  63. tt
  64. turn
  65. unicorn
  66. unicorn_rails
  67. }"
  68. for CMD in $BUNDLED_COMMANDS; do
  69. if [[ $CMD != "bundle" && $CMD != "gem" ]]; then
  70. alias $CMD="run-with-bundler $CMD"
  71. fi
  72. done