bundler.plugin.zsh 1.0 KB

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