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. cap
  30. capify
  31. chefspec
  32. chef-apply
  33. chef-client
  34. chef-shell
  35. chef-solo
  36. cucumber
  37. foodcritic
  38. foreman
  39. guard
  40. haml
  41. html2haml
  42. jasmine
  43. jekyll
  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