Last active
June 1, 2016 21:19
-
-
Save jeanlescure/3cfd8a819a1e2f7defa1bcac44e3f194 to your computer and use it in GitHub Desktop.
Get ruby version from a project regardless of version manager used
This file contains hidden or 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 | |
echo 'Checking for ruby version in $RBENV_VERSION env var...' | |
if [ -n "$RBENV_VERSION" ]; then | |
VERSION=$RBENV_VERSION | |
fi | |
if [ -z ${VERSION+x} ]; then | |
echo 'Checking for ruby version in .ruby-version file...' | |
if [ -f ./.ruby-version ]; then | |
VERSION=`cat .ruby-version | tr -d '\n'` | |
fi | |
fi | |
if [ -z ${VERSION+x} ]; then | |
echo 'Checking for ruby version in .rvmrc file...' | |
if [ -f ./.rvmrc ]; then | |
[[ `cat .rvmrc | sed -e 's/\s*#[^!].*$//'` =~ environment_id\=[\'\"]([^\'\"]*)[\'\"] ]] && VERSION=${BASH_REMATCH[1]} | |
fi | |
fi | |
if [ -z ${VERSION+x} ]; then | |
echo 'Checking for ruby version in Gemfile...' | |
if [ -f ./Gemfile ]; then | |
[[ `cat Gemfile | sed -e 's/\s*#[^!].*$//'` =~ [^#][[:space:]]*ruby[[:space:]]*[\'\"]([^\'\"]*)[\'\"] ]] && VERSION=${BASH_REMATCH[1]} | |
fi | |
fi | |
if [ -z ${VERSION+x} ]; then | |
echo 'NO RUBY VERSION FOUND!' | |
exit | |
fi | |
echo "$VERSION found!" | |
## Un-comment to use RVM | |
# | |
# rvm install $VERSION | |
# rvm use $VERSION | |
## Un-comment to use rbenv | |
# | |
# rbenv install $VERSION | |
# rbenv global $VERSION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment