bundler-exec.plugin.zsh 723 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 dir="$(pwd)"
  12. while [ "$(dirname $dir)" != "/" ]; do
  13. [ -f "$dir/Gemfile" ] && return
  14. dir="$(dirname $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