Last active
September 27, 2015 13:28
-
-
Save AggroBoy/1277568 to your computer and use it in GitHub Desktop.
Script for running Ruby apps. See http://null-terminated.org/blog/2011/10/12/a-simple-ruby-runner-script/
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
#!/usr/bin/env zsh | |
# Set up RVM | |
if [[ -f $HOME/.rvm/scripts/rvm ]]; then | |
source "$HOME/.rvm/scripts/rvm" | |
elif [[ -f /etc/profile.d/rvm.sh ]]; then | |
source /etc/profile.d/rvm.sh | |
else | |
echo RVM not found | |
exit | |
fi | |
# Get the directory we're running in | |
DIR=$(dirname $(perl -e 'use Cwd "abs_path";print abs_path(shift)' $0)) | |
rvm $(cat $DIR/.ruby-version)@$(cat $DIR/.ruby-gemset) | |
# Find some Ruby script to run based on the name of this script | |
if [[ -f $DIR/bin/$(basename $0).rb ]] then | |
ruby -I $DIR/lib $DIR/bin/$(basename $0).rb $@ | |
elif [[ -f $DIR/bin/$(basename $0) ]] then | |
ruby -I $DIR/lib $DIR/bin/$(basename $0) $@ | |
else | |
echo 'so, um...?' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Second revision allows target Ruby script to either have a .rb file extension, or not.