bundler-exec.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. foreman
  51. guard
  52. haml
  53. html2haml
  54. jasmine
  55. jekyll
  56. kitchen
  57. knife
  58. middleman
  59. pry
  60. rackup
  61. rake
  62. rake2thor
  63. rspec
  64. ruby
  65. sass
  66. sass-convert
  67. serve
  68. shotgun
  69. spec
  70. spork
  71. strainer
  72. thin
  73. thor
  74. tilt
  75. tt
  76. turn
  77. unicorn
  78. unicorn_rails
  79. wagon
  80. }"
  81. define-bundler-aliases
  82. unset -f define-bundler-aliases