Created
October 26, 2011 15:17
-
-
Save travisjeffery/1316656 to your computer and use it in GitHub Desktop.
Automagical Bundle Exec (ZSH)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BUNDLED_COMMANDS=(rails rake rspec ruby sass sass-convert spec spork) | |
is-bundler-installed() | |
{ | |
which bundle > /dev/null 2>&1 | |
} | |
is-within-bundled-project() | |
{ | |
local dir="$(pwd)" | |
while [ "$(dirname $dir)" != "/" ]; do | |
[ -f "$dir/Gemfile" ] && return | |
dir="$(dirname $dir)" | |
done | |
false | |
} | |
run-with-bundler() | |
{ | |
if is-bundler-installed && is-within-bundled-project; then | |
bundle exec $@ | |
else | |
$@ | |
fi | |
} | |
for CMD in $BUNDLED_COMMANDS; do | |
alias $CMD="run-with-bundler $CMD" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment