2011-06-12 13:13:39 +02:00
|
|
|
# This plugin is based on https://github.com/gma/bundler-exec
|
2011-06-12 23:16:47 +02:00
|
|
|
# modify the bundled_commands if needed
|
2011-06-12 13:13:39 +02:00
|
|
|
|
2011-06-12 15:52:58 +02:00
|
|
|
bundled_commands=(cucumber heroku rackup rails rake rspec ruby shotgun spec spork)
|
2011-06-12 13:13:39 +02:00
|
|
|
|
|
|
|
## Functions
|
|
|
|
|
2011-06-12 23:16:47 +02:00
|
|
|
_bundler-installed() {
|
2011-06-12 13:13:39 +02:00
|
|
|
which bundle > /dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2011-06-12 23:16:47 +02:00
|
|
|
_within-bundled-project() {
|
2011-06-12 19:16:04 +02:00
|
|
|
local check_dir=$PWD
|
|
|
|
while [ "$(dirname $check_dir)" != "/" ]; do
|
|
|
|
[ -f "$check_dir/Gemfile" ] && return
|
2011-06-12 20:28:27 +02:00
|
|
|
check_dir="$(dirname $check_dir)"
|
2011-06-12 13:13:39 +02:00
|
|
|
done
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2011-06-12 23:16:47 +02:00
|
|
|
_run-with-bundler() {
|
2011-06-12 13:13:39 +02:00
|
|
|
local command="$1"
|
|
|
|
shift
|
2011-06-12 19:16:04 +02:00
|
|
|
if _bundler-installed && _within-bundled-project; then
|
2011-06-12 13:13:39 +02:00
|
|
|
bundle exec $command "$@"
|
|
|
|
else
|
2011-06-12 20:28:27 +02:00
|
|
|
$command "$@"
|
2011-06-12 13:13:39 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Main program
|
2011-06-12 15:52:58 +02:00
|
|
|
for cmd in $bundled_commands; do
|
2011-06-12 19:16:04 +02:00
|
|
|
alias $cmd="_run-with-bundler $cmd"
|
2011-06-12 13:13:39 +02:00
|
|
|
done
|