9e819435 |
# This plugin is based on https://github.com/gma/bundler-exec |
69d30a63 |
# modify the bundled_commands if needed |
9e819435 |
|
05883f38 |
bundled_commands=(cucumber heroku rackup rails rake rspec ruby shotgun spec spork) |
9e819435 |
## Functions
|
69d30a63 |
_bundler-installed() { |
9e819435 |
which bundle > /dev/null 2>&1
}
|
69d30a63 |
_within-bundled-project() { |
3aee5c19 |
local check_dir=$PWD
while [ "$(dirname $check_dir)" != "/" ]; do
[ -f "$check_dir/Gemfile" ] && return |
86958a32 |
check_dir="$(dirname $check_dir)" |
9e819435 |
done
false
}
|
69d30a63 |
_run-with-bundler() { |
9e819435 |
local command="$1"
shift |
3aee5c19 |
if _bundler-installed && _within-bundled-project; then |
9e819435 |
bundle exec $command "$@"
else |
86958a32 |
$command "$@" |
9e819435 |
fi
}
## Main program |
05883f38 |
for cmd in $bundled_commands; do |
3aee5c19 |
alias $cmd="_run-with-bundler $cmd" |
9e819435 |
done |