Skip to content

Instantly share code, notes, and snippets.

@travisjeffery
Created October 26, 2011 15:17
Show Gist options
  • Save travisjeffery/1316656 to your computer and use it in GitHub Desktop.
Save travisjeffery/1316656 to your computer and use it in GitHub Desktop.
Automagical Bundle Exec (ZSH)
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