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

35 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
2011-06-12 21:16:47 +00:00
# modify the bundled_commands if needed
2011-06-12 11:13:39 +00:00
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 21:16:47 +00:00
_bundler-installed() {
2011-06-12 11:13:39 +00:00
which bundle > /dev/null 2>&1
}
2011-06-12 21:16:47 +00:00
_within-bundled-project() {
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 21:16:47 +00:00
_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