#!/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