oh-my-zsh/plugins/bundler-exec/bundler-exec.plugin.zsh

38 lines
753 B
Bash
Raw Normal View History

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
_bundler-installed()
2011-06-12 11:13:39 +00:00
{
which bundle > /dev/null 2>&1
}
_within-bundled-project()
2011-06-12 11:13:39 +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
}
_run-with-bundler()
2011-06-12 11:13:39 +00:00
{
local command="$1"
shift
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
alias $cmd="_run-with-bundler $cmd"
2011-06-12 11:13:39 +00:00
done