Skip to content

Instantly share code, notes, and snippets.

@etrepat
Created December 12, 2011 11:03
Show Gist options
  • Save etrepat/1466610 to your computer and use it in GitHub Desktop.
Save etrepat/1466610 to your computer and use it in GitHub Desktop.
Automatically run Ruby scripts with "bundle exec". Source: gma/bundler-exec
#!/bin/bash
BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
cap
capify
cucumber
foreman
guard
haml
heroku
html2haml
rackup
rails
rake
rake2thor
rspec
ruby
sass
sass-convert
serve
shotgun
spec
spork
thin
thor
tilt
tt
turn
unicorn
unicorn_rails
}"
## Functions
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
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