Last active
December 31, 2015 19:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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