bundler.plugin.zsh 765 B

123456789101112131415161718192021222324252627282930313233343536
  1. alias be="bundle exec"
  2. alias bi="bundle install"
  3. alias bl="bundle list"
  4. alias bu="bundle update"
  5. # The following is based on https://github.com/gma/bundler-exec
  6. bundled_commands=(cap capify cucumber heroku rackup rails rake rspec ruby shotgun spec spork thin unicorn unicorn_rails)
  7. ## Functions
  8. _bundler-installed() {
  9. which bundle > /dev/null 2>&1
  10. }
  11. _within-bundled-project() {
  12. local check_dir=$PWD
  13. while [ "$(dirname $check_dir)" != "/" ]; do
  14. [ -f "$check_dir/Gemfile" ] && return
  15. check_dir="$(dirname $check_dir)"
  16. done
  17. false
  18. }
  19. _run-with-bundler() {
  20. if _bundler-installed && _within-bundled-project; then
  21. bundle exec $@
  22. else
  23. $@
  24. fi
  25. }
  26. ## Main program
  27. for cmd in $bundled_commands; do
  28. alias $cmd="_run-with-bundler $cmd"
  29. done