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