bundler.plugin.zsh 1.2 KB

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