bundler-exec.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. define-bundler-aliases()
  28. {
  29. # Allow zsh to iterate over list of words
  30. [ -n "$ZSH_VERSION" ] && setopt localoptions shwordsplit
  31. local command
  32. for command in $BUNDLED_COMMANDS; do
  33. if [[ $command != "bundle" && $command != "gem" ]]; then
  34. alias $command="run-with-bundler $command"
  35. fi
  36. done
  37. }
  38. ## Main program
  39. BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
  40. cap
  41. capify
  42. chef
  43. chefspec
  44. chef-apply
  45. chef-client
  46. chef-shell
  47. chef-solo
  48. cucumber
  49. foodcritic
  50. guard
  51. haml
  52. html2haml
  53. jasmine
  54. jekyll
  55. kitchen
  56. knife
  57. middleman
  58. pry
  59. rackup
  60. rails
  61. rake
  62. rake2thor
  63. rspec
  64. ruby
  65. sass
  66. sass-convert
  67. serve
  68. shotgun
  69. sidekiq
  70. spec
  71. spork
  72. strainer
  73. thin
  74. thor
  75. tilt
  76. tt
  77. turn
  78. unicorn
  79. unicorn_rails
  80. wagon
  81. }"
  82. define-bundler-aliases
  83. unset -f define-bundler-aliases