Skip to content

Instantly share code, notes, and snippets.

@aaronfeng
Last active December 31, 2015 19:09
Show Gist options
  • Save aaronfeng/8031676 to your computer and use it in GitHub Desktop.
Save aaronfeng/8031676 to your computer and use it in GitHub Desktop.
Intercepts `ruby` in order to prepend `bundle exec` if Gemfile.lock is present
#!/bin/bash
# remember original ruby location
export CURRENT_RUBY=$(which ruby)
alias ruby="ruby_wrapper"
# call bundle exec if there's a Gemfile.lock
function ruby_wrapper() {
# unalias it to get the real ruby version
# this is require if ruby was switch via rvm or rbenv
unalias ruby
CURRENT_RUBY=$(which ruby)
if [ -e "$(pwd)/Gemfile.lock" ]
then
bundle exec $CURRENT_RUBY "$@"
else
$CURRENT_RUBY "$@"
fi
# set the alias back for next interception
alias ruby="ruby_wrapper"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment