|
@@ -1,16 +1,46 @@
|
|
|
#!/bin/bash
|
|
|
|
|
|
+## Functions
|
|
|
+
|
|
|
rbenv-installed()
|
|
|
{
|
|
|
- which rbenv > /dev/null 2>&1
|
|
|
+ which rbenv > /dev/null 2>&1
|
|
|
}
|
|
|
|
|
|
+bundler-installed()
|
|
|
+{
|
|
|
+ if rbenv-installed; then
|
|
|
+ rbenv which bundle > /dev/null 2>&1
|
|
|
+ else
|
|
|
+ which bundle > /dev/null 2>&1
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+within-bundled-project()
|
|
|
+{
|
|
|
+ local dir="$(pwd)"
|
|
|
+ while [ "$(dirname $dir)" != "/" ]; do
|
|
|
+ [ -f "$dir/Gemfile" ] && return
|
|
|
+ dir="$(dirname $dir)"
|
|
|
+ done
|
|
|
+ false
|
|
|
+}
|
|
|
+
|
|
|
+run-with-bundler()
|
|
|
+{
|
|
|
+ if bundler-installed && within-bundled-project; then
|
|
|
+ bundle exec $@
|
|
|
+ else
|
|
|
+ $@
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+## Main program
|
|
|
|
|
|
if rbenv-installed; then
|
|
|
- BUNDLED_COMMANDS=$(ls ~/.rbenv/shims)
|
|
|
+ BUNDLED_COMMANDS=$(ls ~/.rbenv/shims)
|
|
|
else
|
|
|
-
|
|
|
-BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
|
|
|
+ BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
|
|
|
cap
|
|
|
capify
|
|
|
cucumber
|
|
@@ -39,43 +69,10 @@ turn
|
|
|
unicorn
|
|
|
unicorn_rails
|
|
|
}"
|
|
|
-
|
|
|
fi
|
|
|
|
|
|
-## Functions
|
|
|
-
|
|
|
-bundler-installed()
|
|
|
-{
|
|
|
- if rbenv-installed; then
|
|
|
- rbenv which bundle > /dev/null 2>&1
|
|
|
- else
|
|
|
- which bundle > /dev/null 2>&1
|
|
|
- fi
|
|
|
-}
|
|
|
-
|
|
|
-within-bundled-project()
|
|
|
-{
|
|
|
- local dir="$(pwd)"
|
|
|
- while [ "$(dirname $dir)" != "/" ]; do
|
|
|
- [ -f "$dir/Gemfile" ] && return
|
|
|
- dir="$(dirname $dir)"
|
|
|
- done
|
|
|
- false
|
|
|
-}
|
|
|
-
|
|
|
-run-with-bundler()
|
|
|
-{
|
|
|
- if bundler-installed && within-bundled-project; then
|
|
|
- bundle exec $@
|
|
|
- else
|
|
|
- $@
|
|
|
- fi
|
|
|
-}
|
|
|
-
|
|
|
-## Main program
|
|
|
-
|
|
|
for CMD in $BUNDLED_COMMANDS; do
|
|
|
- if [[ $CMD != 'bundle' && $CMD != 'gem' ]]; then
|
|
|
- alias $CMD="run-with-bundler $CMD"
|
|
|
- fi
|
|
|
+ if [[ $CMD != "bundle" && $CMD != "gem" ]]; then
|
|
|
+ alias $CMD="run-with-bundler $CMD"
|
|
|
+ fi
|
|
|
done
|