bundler.plugin.zsh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # The following is based on https://github.com/gma/bundler-exec
  7. 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)
  8. ## Functions
  9. _bundler-installed() {
  10. which bundle > /dev/null 2>&1
  11. }
  12. _within-bundled-project() {
  13. local check_dir=$PWD
  14. while [ $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. if _bundler-installed; then
  28. bundler_version=`bundle version | cut -d' ' -f3`
  29. if [[ $bundler_version > '1.4.0' || $bundler_version = '1.4.0' ]]; then
  30. if [[ "$(uname)" == 'Darwin' ]]
  31. then
  32. local cores_num="$(sysctl hw.ncpu | awk '{print $2}')"
  33. else
  34. local cores_num="$(nproc)"
  35. fi
  36. eval "alias bi='bundle install --jobs=$cores_num'"
  37. else
  38. alias bi='bundle install'
  39. fi
  40. ## Main program
  41. for cmd in $bundled_commands; do
  42. eval "function unbundled_$cmd () { $cmd \$@ }"
  43. eval "function bundled_$cmd () { _run-with-bundler $cmd \$@}"
  44. alias $cmd=bundled_$cmd
  45. if which _$cmd > /dev/null 2>&1; then
  46. compdef _$cmd bundled_$cmd=$cmd
  47. fi
  48. done
  49. fi