bundler.plugin.zsh 1.0 KB

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