Skip to content

Commit

Permalink
Improve rbenv switching with error messages for invalid Rubies (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
BytesGuy authored Jan 27, 2023
1 parent 65863e8 commit 93016e6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/scripts/switch-ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ if ! [ -x "$(command -v rbenv)" ]; then
echo "chruby $ruby_version" >> ~/.bash_profile
fi
else
version="$ORB_VAL_RUBY_VERSION"
needs_fuzzy_matching=$(echo "$ORB_VAL_RUBY_VERSION" | awk -F. '{print NF-1}')

if [[ $needs_fuzzy_matching == 1 && "$ORB_VAL_RUBY_VERSION" != "system" ]]; then
# shellcheck disable=SC2154
version=$(rbenv versions --bare | grep "$ORB_VAL_RUBY_VERSION" | head -n 1)
version=$(rbenv versions --bare | grep "$ORB_VAL_RUBY_VERSION" | head -n 1)
if [ -z "$version" ]; then
printf "\nNo Rubies installed that match version %s\n" "$ORB_VAL_RUBY_VERSION"
printf "\nInstalled versions:\n"
rbenv versions
exit 1
fi

rbenv global "$version"
rbenv rehash

printf "\nSet Ruby version succesfully:\n"
rbenv versions
fi

0 comments on commit 93016e6

Please sign in to comment.