sort rubies versions properly#277
sort rubies versions properly#277grimm26 wants to merge 3 commits intopostmodern:masterfrom grimm26:sortv
Conversation
|
A problem with using GNU's |
|
I wonder if we could get away with falling back to normal |
|
I think that doing a check for proper |
|
Can we get away with |
|
@aprescott Yeah, @mpapis suggested about the same and I think it may be viable. We do need to sort after the last slash because |
|
Yes, it is more complicated than using sort. Witness: Sorting the first field numerically doesn't order these example rubies correctly. We can change the first sort to numeric: Looks much better, right? Until a ruby goes double digits: The sort needs to be by ruby type (rbi vs ruby, etc) and then sorted on just the isolated version. Without GNU coreutils or perl or something, this is difficult :) |
$ ls -1d ~/.rvm/rubies/* |
sed 'h; s/-/./g ;; s/.*\///g ;; G ; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n |
awk '{print $2}'
/home/mpapis/.rvm/rubies/current
/home/mpapis/.rvm/rubies/default
/home/mpapis/.rvm/rubies/rbx-1.3.3
/home/mpapis/.rvm/rubies/rbx-2.0.0
/home/mpapis/.rvm/rubies/rbx-10.0.0
/home/mpapis/.rvm/rubies/ruby-1.9.3-p545
/home/mpapis/.rvm/rubies/ruby-1.9.3-p547
/home/mpapis/.rvm/rubies/ruby-2.0.0-p481
/home/mpapis/.rvm/rubies/ruby-2.1.2or $ ls -1d ~/.rvm/rubies/* |
sed 's/.*\///g ;; h; s/-/./g ;; G ; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n |
awk '{print $2}'
current
default
rbx-1.3.3
rbx-2.0.0
rbx-10.0.0
ruby-1.9.3-p545
ruby-1.9.3-p547
ruby-2.0.0-p481
ruby-2.1.2the whole magic is in
this works because: $ ls -1d ~/.rvm/rubies/* |
sed -n 'h; s/-/./g ;; s/.*\///g ;; G ; s/\n/ / ;; p ' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n
current /home/mpapis/.rvm/rubies/current
default /home/mpapis/.rvm/rubies/default
rbx.1.3.3 /home/mpapis/.rvm/rubies/rbx-1.3.3
rbx.2.0.0 /home/mpapis/.rvm/rubies/rbx-2.0.0
rbx.10.0.0 /home/mpapis/.rvm/rubies/rbx-10.0.0
ruby.1.9.3.p545 /home/mpapis/.rvm/rubies/ruby-1.9.3-p545
ruby.1.9.3.p547 /home/mpapis/.rvm/rubies/ruby-1.9.3-p547
ruby.2.0.0.p481 /home/mpapis/.rvm/rubies/ruby-2.0.0-p481
ruby.2.1.2 /home/mpapis/.rvm/rubies/ruby-2.1.2and we use |
|
Brilliant! Should have know there was some sed or awk magic that could save the day. I tried this on Linux, darwin, and FreeBSD with success. |
|
sed magic sort now incorporated. |
|
Is this or #278 sufficient to be merged? |
|
closing in deference to #278 since more development has been done. |
Having rbx-2.2.9 and rbx-2.2.10 in rubies and specifying "chruby rbx" would choose rbx-2.2.9 because chruby.sh just globs the contents of the rubies directories and so the members of the RUBIES array are sorted in ascii order: rbx-2.2.9 > rbx-2.2.10.
Using ls -v instead sorts the ruby versions properly.