Created
October 19, 2020 15:17
-
-
Save agrberg/dbc5dcba44204f5cb049727c05474046 to your computer and use it in GitHub Desktop.
Ruby Version updating script
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
function rv() { | |
new_version=${1}; | |
sed_command_base="^ruby.*\([[:digit:]]\.\)*[[:digit:]]*"; | |
if [[ -z "$new_version" ]]; then | |
if [[ -e Gemfile ]]; then | |
echo "Gemfile: $(sed -ne /${sed_command_base}/p Gemfile)"; | |
fi | |
if [[ -e .ruby-version ]]; then | |
echo ".ruby-version: $(sed -ne /${sed_command_base}/p .ruby-version)"; | |
fi | |
else | |
if [[ -e Gemfile ]]; then | |
sed -i '' -e "s/${sed_command_base}/ruby '${new_version}'/" Gemfile; | |
echo 'Gemfile updated'; | |
bundle; | |
fi | |
if [[ -e .ruby-version ]]; then | |
sed -i '' -e s/${sed_command_base}/ruby-${new_version}/ .ruby-version; | |
echo '.ruby-version updated'; | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment