bundler.plugin.zsh 797 B

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