bundler.plugin.zsh 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. alias be="bundle exec"
  2. alias bi="bundle install"
  3. alias bl="bundle list"
  4. alias bp="bundle package"
  5. alias bu="bundle update"
  6. # The following is based on https://github.com/gma/bundler-exec
  7. bundled_commands=(annotate cap capify cucumber foreman guard heroku nanoc rackup rainbows rake rspec ruby shotgun spec spork thin thor 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. eval "function bundled_$cmd () { _run-with-bundler $cmd \$@}"
  30. alias $cmd=bundled_$cmd
  31. if which _$cmd > /dev/null 2>&1; then
  32. compdef _$cmd bundled_$cmd=$cmd
  33. fi
  34. done