diff options
author | Hakan Ensari <hakan.ensari@papercavalier.com> | 2011-07-13 22:41:09 +0100 |
---|---|---|
committer | Hakan Ensari <hakan.ensari@papercavalier.com> | 2011-07-13 22:54:30 +0100 |
commit | 60e104acd1710c04057d079cfa5ac9316762f580 (patch) | |
tree | 67cfa7d6a948375502bc5c9309c47ea884c6bae7 /plugins/bundler/bundler.plugin.zsh | |
parent | a77e6fb003cc80fbbff5d453a5ca3d38638d99ed (diff) | |
download | zsh-60e104acd1710c04057d079cfa5ac9316762f580.tar.gz zsh-60e104acd1710c04057d079cfa5ac9316762f580.tar.bz2 zsh-60e104acd1710c04057d079cfa5ac9316762f580.zip |
merge bundler and bundle-exec plugins
Diffstat (limited to 'plugins/bundler/bundler.plugin.zsh')
-rw-r--r-- | plugins/bundler/bundler.plugin.zsh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/plugins/bundler/bundler.plugin.zsh b/plugins/bundler/bundler.plugin.zsh index fb40e2cec..fcf3e85fc 100644 --- a/plugins/bundler/bundler.plugin.zsh +++ b/plugins/bundler/bundler.plugin.zsh @@ -1,3 +1,37 @@ alias be="bundle exec" alias bi="bundle install" alias bu="bundle update" + +# The following is based on https://github.com/gma/bundler-exec + +bundled_commands=(cap capify cucumber heroku rackup rails rake rspec ruby shotgun spec spork thin unicorn unicorn_rails) + +## Functions + +_bundler-installed() { + which bundle > /dev/null 2>&1 +} + +_within-bundled-project() { + local check_dir=$PWD + while [ "$(dirname $check_dir)" != "/" ]; do + [ -f "$check_dir/Gemfile" ] && return + check_dir="$(dirname $check_dir)" + done + false +} + +_run-with-bundler() { + local command="$1" + shift + if _bundler-installed && _within-bundled-project; then + bundle exec $command "$@" + else + $command "$@" + fi +} + +## Main program +for cmd in $bundled_commands; do + alias $cmd="_run-with-bundler $cmd" +done |