9e8194355c1a4f69dc52fbe2699fbce1be5c6493
- Author
- Bodo Tasche <bodo@wannawork.de>
- Committer
- Hakan Ensari <hakan.ensari@papercavalier.com>
- Date
Message
Added bundler-exec plugin
Diff
1diff --git a/plugins/bundler-exec/bundler-exec.plugin.zsh b/plugins/bundler-exec/bundler-exec.plugin.zsh
2new file mode 100644
3index 0000000000000000000000000000000000000000..966725976fe0503e7106dd2013875bf45508dbfc
4--- /dev/null
5+++ b/plugins/bundler-exec/bundler-exec.plugin.zsh
6@@ -0,0 +1,37 @@
7+# This plugin is based on https://github.com/gma/bundler-exec
8+# modify the BUNDLED_COMMANDS if needed
9+
10+BUNDLED_COMMANDS=(cucumber heroku rackup rails rake rspec ruby shotgun spec spork)
11+
12+## Functions
13+
14+bundler-installed()
15+{
16+ which bundle > /dev/null 2>&1
17+}
18+
19+within-bundled-project()
20+{
21+ local dir="$(pwd)"
22+ while [ "$(dirname $dir)" != "/" ]; do
23+ [ -f "$dir/Gemfile" ] && return
24+ dir="$(dirname $dir)"
25+ done
26+ false
27+}
28+
29+run-with-bundler()
30+{
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