Browse code

Added bundler-exec plugin

Bodo Tasche authored on 12/06/2011 at 11:13:39
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+# This plugin is based on https://github.com/gma/bundler-exec
1
+# modify the BUNDLED_COMMANDS if needed
2
+
3
+BUNDLED_COMMANDS=(cucumber heroku rackup rails rake rspec ruby shotgun spec spork)
4
+
5
+## Functions
6
+
7
+bundler-installed()
8
+{
9
+    which bundle > /dev/null 2>&1
10
+}
11
+
12
+within-bundled-project()
13
+{
14
+    local dir="$(pwd)"
15
+    while [ "$(dirname $dir)" != "/" ]; do
16
+        [ -f "$dir/Gemfile" ] && return
17
+        dir="$(dirname $dir)"
18
+    done
19
+    false
20
+}
21
+
22
+run-with-bundler()
23
+{
24
+    local command="$1"
25
+    shift
26
+    if bundler-installed && within-bundled-project; then
27
+        bundle exec $command "$@"
28
+    else
29
+        $command "$@"
30
+    fi
31
+}
32
+
33
+## Main program
34
+for CMD in $BUNDLED_COMMANDS; do
35
+   alias $CMD="run-with-bundler $CMD"
36
+done