bundler-exec.plugin.zsh 756 B

12345678910111213141516171819202122232425262728293031323334
  1. # This plugin is based on https://github.com/gma/bundler-exec
  2. # modify the bundled_commands if needed
  3. bundled_commands=(cap capify cucumber heroku rackup rails rake rspec ruby shotgun spec spork thin unicorn unicorn_rails)
  4. ## Functions
  5. _bundler-installed() {
  6. which bundle > /dev/null 2>&1
  7. }
  8. _within-bundled-project() {
  9. local check_dir=$PWD
  10. while [ "$(dirname $check_dir)" != "/" ]; do
  11. [ -f "$check_dir/Gemfile" ] && return
  12. check_dir="$(dirname $check_dir)"
  13. done
  14. false
  15. }
  16. _run-with-bundler() {
  17. local command="$1"
  18. shift
  19. if _bundler-installed && _within-bundled-project; then
  20. bundle exec $command "$@"
  21. else
  22. $command "$@"
  23. fi
  24. }
  25. ## Main program
  26. for cmd in $bundled_commands; do
  27. alias $cmd="_run-with-bundler $cmd"
  28. done