- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Natural sort RUBIES by version. #278
base: master
Are you sure you want to change the base?
Conversation
- Uses the find command for building the RUBIES array. - Uses a variant of mpapis's sed/sort code for natural version sorting.
f566a3e
to
d0a6f1d
Compare
1871180
to
9e7f0e4
Compare
any ETA for a merge and release? It's troublesome that |
@jrochkind random question, but why do you keep around older ruby versions? |
@postmodern good question. I think you're right that in this case it was just absent-mindedness, and I can take care of my immediate problem by removing old versions. And remembering to remove old versions every time I install a new version. There have been about 2 times in the past when i was reporting a bug to jruby, and needed to switch back and forth among jruby versions to determine exactly where the bug exhibited. My bug-work may have been off-and-on over a couple weeks, in the midst of which I was doing other 'normal' work and wanted And of course I keep old versions of MRI around in order to run tests of gems I work on against multiple versions of ruby, but since they would be invoked with There might be other weird edge cases I'm not thinking of now. You're right they are edge cases, and remembering to clean up old rubies would take care of the bulk of the annoyance. But they do crop up from time to time, and it has been very nice that I don't need to think about "is this an edge case? Do I have old versions around for a reason or for no reason? How might it effect chruby?", and could just count on Make sense? |
Was reading this PR looking for a way to As a gem author, I frequently need to use old versions as far back as 1.9 to reproduce build failures on my local machine. I think it's a valid use-case. |
Ran into this again today (merry christmas!) #387 |
Anyone have a good way to "monkey-patch" this into chruby, while still being able to update to any new releases of chruby, if postmodern is still not interested in merging? Or maybe new releases of chruby don't come out so much that I should be scared to just use a fork? My life would still be easier with this feature. |
A nice turn of events is that macOS and the BSDs are now supporting function chruby_rubies()
{
local rubies
rubies=()
for dir in "$@"; do
[[ -d "$dir" && -n "$(command ls -A "$dir")" ]] && rubies+=("$dir"/*)
done
printf "%b\n" "${rubies[@]}" | sort --version-sort | xargs
}
RUBIES=("$(chruby_rubies "$PREFIX/opt/rubies" "$HOME/.rubies")") |
@jrochkind You can save the snippet above as |
FYI we are considering controlling |
chruby_rubies()
Extracts detecting and sorting
RUBIES
into a testable function. The function takes the default Ruby auto-detection directories as arguments and returns a natural Ruby version sorted list of Ruby directories.Description
FirstReplacedfind
searches the auto-detection directories one level deep for any Ruby directories (using-mindepth
and-maxdepth
due to portability issues with-d
). Then the detected Ruby directories are sorted using a slight variation of @mpapis’ natural version sorting code from #277 (closes #277, see @mpapis’ explanation of the code there for details).find
andsed
with a shell implementation.The originally detected Ruby directory paths are stored, a copy is mapped to its basename with the first dash replaced with a period, and the stored original is appended to its corresponding sort-friendly basename. Finally, the basenames are dictionary sorted by Ruby name and then numeric sorted by MAJOR, MINOR, and TINY versions.
The PATCH version column is not numeric sorted since a simple numeric sort is ineffective due to the "p" prefix and it's incidentally correctly ordered by
find
for all supported patch versions. I think it's okay to leave it at that since with adoption of semantic versioning there's no worry about new patch versions incoming.