Skip to content

Instantly share code, notes, and snippets.

@expectedbehavior
Created September 20, 2010 17:43
Show Gist options
  • Save expectedbehavior/588297 to your computer and use it in GitHub Desktop.
Save expectedbehavior/588297 to your computer and use it in GitHub Desktop.
[ -f ~/.bundler-exec.sh ] && source ~/.bundler-exec.sh
#!/bin/bash
BUNDLED_COMMANDS="spec rspec cucumber cap css2sass sass-convert html2haml rackup rake resque resque-web"
## Functions
bundler-installed()
{
which bundle > /dev/null 2>&1
}
within-bundled-project()
{
local dir="$(pwd)"
while [ "$(dirname $dir)" != "$HOME" ]; do
[ -f "$dir/Gemfile" ] && return
dir="$(dirname $dir)"
done
false
}
run-with-bundler()
{
local command="$1"
local dir="$(pwd)"
shift
if bundler-installed && within-bundled-project; then
if [ -f "$dir/bin/$command" ]; then
$dir/bin/$command "$@"
else
bundle exec $command "$@"
fi
else
$command "$@"
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