Skip to content

Instantly share code, notes, and snippets.

@agrberg
Created October 19, 2020 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrberg/dbc5dcba44204f5cb049727c05474046 to your computer and use it in GitHub Desktop.
Save agrberg/dbc5dcba44204f5cb049727c05474046 to your computer and use it in GitHub Desktop.
Ruby Version updating script
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