bundler-exec.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. kitchen
  44. knife
  45. middleman
  46. pry
  47. rackup
  48. rake
  49. rake2thor
  50. rspec
  51. ruby
  52. sass
  53. sass-convert
  54. serve
  55. shotgun
  56. spec
  57. spork
  58. strainer
  59. thin
  60. thor
  61. tilt
  62. tt
  63. turn
  64. unicorn
  65. unicorn_rails
  66. }"
  67. for CMD in $BUNDLED_COMMANDS; do
  68. if [[ $CMD != "bundle" && $CMD != "gem" ]]; then
  69. alias $CMD="run-with-bundler $CMD"
  70. fi
  71. done