Skip to content

Instantly share code, notes, and snippets.

@danielspector
Created March 3, 2014 16:09
Show Gist options
  • Select an option

  • Save danielspector/9328293 to your computer and use it in GitHub Desktop.

Select an option

Save danielspector/9328293 to your computer and use it in GitHub Desktop.
bundler-installed()
{
which bundle > /dev/null 2>&1
}
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
BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
berks
cap
capify
chefspec
chef-apply
chef-client
chef-shell
chef-solo
cucumber
foodcritic
foreman
guard
haml
html2haml
jasmine
kitchen
knife
pry
rackup
rake
rake2thor
rspec
ruby
sass
sass-convert
serve
shotgun
spec
spork
strainer
thin
thor
tilt
tt
turn
tux
unicorn
unicorn_rails
}"
for CMD in $BUNDLED_COMMANDS; do
if [[ $CMD != "bundle" && $CMD != "gem" ]]; then
alias $CMD="run-with-bundler $CMD"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment