9e601c23f15a7da60ba8c17f4da0d85cd6bbb49e

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #462 from papercavalier/bundler

Bundler plugin consolidation

Diff

 1diff --git a/plugins/bundler/bundler.plugin.zsh b/plugins/bundler/bundler.plugin.zsh
 2index fb40e2cec10dc79da5875c660d18d70d4ee9ac10..c91dc9ab9c509ce71801df1b0287fe910ef429a4 100644
 3--- a/plugins/bundler/bundler.plugin.zsh
 4+++ b/plugins/bundler/bundler.plugin.zsh
 5@@ -1,3 +1,38 @@
 6 alias be="bundle exec"
 7 alias bi="bundle install"
 8+alias bl="bundle list"
 9 alias bu="bundle update"
10+
11+# The following is based on https://github.com/gma/bundler-exec
12+
13+bundled_commands=(cap capify cucumber heroku rackup rails rake rspec ruby shotgun spec spork thin unicorn unicorn_rails)
14+
15+## Functions
16+
17+_bundler-installed() {
18+  which bundle > /dev/null 2>&1
19+}
20+
21+_within-bundled-project() {
22+  local check_dir=$PWD
23+  while [ "$(dirname $check_dir)" != "/" ]; do
24+    [ -f "$check_dir/Gemfile" ] && return
25+    check_dir="$(dirname $check_dir)"
26+  done
27+  false
28+}
29+
30+_run-with-bundler() {
31+  local command="$1"
32+  shift
33+  if _bundler-installed && _within-bundled-project; then
34+    bundle exec $command "$@"
35+  else
36+    $command "$@"
37+  fi
38+}
39+
40+## Main program
41+for cmd in $bundled_commands; do
42+  alias $cmd="_run-with-bundler $cmd"
43+done
44diff --git a/plugins/rails3/rails3.plugin.zsh b/plugins/rails3/rails3.plugin.zsh
45index f669ef047c74e687edd446649f9d74e0c6eed87d..f4ee637e6b45522afdee404804b12edf0f1e992e 100644
46--- a/plugins/rails3/rails3.plugin.zsh
47+++ b/plugins/rails3/rails3.plugin.zsh
48@@ -1,13 +1,5 @@
49 # Rails 3 aliases, backwards-compatible with Rails 2.
50 
51-function _bundle_command {
52-  if command -v bundle && [ -e "Gemfile" ]; then
53-    bundle exec $@
54-  else
55-    $@
56-  fi
57-}
58-
59 function _rails_command () {
60   if [ -e "script/server" ]; then
61     ruby script/$@
62@@ -25,6 +17,3 @@ alias rp='_rails_command plugin'
63 alias rs='_rails_command server'
64 alias rsd='_rails_command server --debugger'
65 alias devlog='tail -f log/development.log'
66-
67-alias rspec='_bundle_command rspec'
68-alias cuke='_bundle_command cucumber'