bundler-exec.plugin.zsh 749 B

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