bundler.plugin.zsh 816 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. local command="$1"
  21. shift
  22. if _bundler-installed && _within-bundled-project; then
  23. bundle exec $command "$@"
  24. else
  25. $command "$@"
  26. fi
  27. }
  28. ## Main program
  29. for cmd in $bundled_commands; do
  30. alias $cmd="_run-with-bundler $cmd"
  31. done