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. 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. 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