Browse code

Merge pull request #462 from papercavalier/bundler

Bundler plugin consolidation

Robby Russell authored on 14/07/2011 at 03:20:47
Showing 2 changed files
... ...
@@ -1,3 +1,38 @@
1 1
 alias be="bundle exec"
2 2
 alias bi="bundle install"
3
+alias bl="bundle list"
3 4
 alias bu="bundle update"
5
+
6
+# The following is based on https://github.com/gma/bundler-exec
7
+
8
+bundled_commands=(cap capify cucumber heroku rackup rails rake rspec ruby shotgun spec spork thin unicorn unicorn_rails)
9
+
10
+## Functions
11
+
12
+_bundler-installed() {
13
+  which bundle > /dev/null 2>&1
14
+}
15
+
16
+_within-bundled-project() {
17
+  local check_dir=$PWD
18
+  while [ "$(dirname $check_dir)" != "/" ]; do
19
+    [ -f "$check_dir/Gemfile" ] && return
20
+    check_dir="$(dirname $check_dir)"
21
+  done
22
+  false
23
+}
24
+
25
+_run-with-bundler() {
26
+  local command="$1"
27
+  shift
28
+  if _bundler-installed && _within-bundled-project; then
29
+    bundle exec $command "$@"
30
+  else
31
+    $command "$@"
32
+  fi
33
+}
34
+
35
+## Main program
36
+for cmd in $bundled_commands; do
37
+  alias $cmd="_run-with-bundler $cmd"
38
+done
... ...
@@ -1,13 +1,5 @@
1 1
 # Rails 3 aliases, backwards-compatible with Rails 2.
2 2
 
3
-function _bundle_command {
4
-  if command -v bundle && [ -e "Gemfile" ]; then
5
-    bundle exec $@
6
-  else
7
-    $@
8
-  fi
9
-}
10
-
11 3
 function _rails_command () {
12 4
   if [ -e "script/server" ]; then
13 5
     ruby script/$@
... ...
@@ -25,6 +17,3 @@ alias rp='_rails_command plugin'
25 25
 alias rs='_rails_command server'
26 26
 alias rsd='_rails_command server --debugger'
27 27
 alias devlog='tail -f log/development.log'
28
-
29
-alias rspec='_bundle_command rspec'
30
-alias cuke='_bundle_command cucumber'