bundler-exec.sh 1.1 KB

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