Skip to content
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

'versionsort' messes up sorting outside of numbers #801

Closed
eugenesvk opened this issue Jan 15, 2023 · 9 comments
Closed

'versionsort' messes up sorting outside of numbers #801

eugenesvk opened this issue Jan 15, 2023 · 9 comments
Assignees
Labels
kind/bug Something isn't working

Comments

@eugenesvk
Copy link

  • os: macOS 10.15
  • lsd --version: lsd 0.23.1
  • echo $TERM: xterm-256color
  • echo $LS_COLORS: #=90:.7z=38;5;160:.aac=38;5;37:.ace=38;5;160:.alz=38;5;160:.arc=38;5;160:.arj=38;5;160:.asf=38;5;170:.au=38;5;37:.avi=38;5;170:.avif=38;5;170:.bak=90:.bmp=38;5;170:.bz=38;5;160:.bz2=38;5;160:.cab=38;5;160:.cgm=38;5;170:.cpio=38;5;160:.deb=38;5;160:.dl=38;5;170:.dpkg-dist=90:.dpkg-old=90:.dwm=38;5;160:.dz=38;5;160:.ear=38;5;160:.emf=38;5;170:.esd=38;5;160:.flac=38;5;37:.flc=38;5;170:.fli=38;5;170:.flv=38;5;170:.gif=38;5;170:.gl=38;5;170:.gz=38;5;160:.jar=38;5;160:.jpeg=38;5;170:.jpg=38;5;170:.lha=38;5;160:.lrz=38;5;160:.lz=38;5;160:.lz4=38;5;160:.lzh=38;5;160:.lzma=38;5;160:.lzo=38;5;160:.m2v=38;5;170:.m4a=38;5;37:.m4v=38;5;170:.mid=38;5;37:.midi=38;5;37:.mjpeg=38;5;170:.mjpg=38;5;170:.mka=38;5;37:.mkv=38;5;170:.mng=38;5;170:.mov=38;5;170:.mp3=38;5;37:.mp4=38;5;170:.mp4v=38;5;170:.mpc=38;5;37:.mpeg=38;5;170:.mpg=38;5;170:.nuv=38;5;170:.oga=38;5;37:.ogg=38;5;37:.ogm=38;5;170:.ogv=38;5;170:.ogx=38;5;170:.old=90:.opus=38;5;37:.orig=90:.part=90:.pbm=38;5;170:.pcx=38;5;170:.pgm=38;5;170:.png=38;5;170:.ppm=38;5;170:.qt=38;5;170:.ra=38;5;37:.rar=38;5;160:.rej=90:.rm=38;5;170:.rmvb=38;5;170:.rpm=38;5;160:.rpmnew=90:.rpmorig=90:.rpmsave=90:.rz=38;5;160:.sar=38;5;160:.spx=38;5;37:.svg=38;5;170:.svgz=38;5;170:.swm=38;5;160:.swp=90:.t7z=38;5;160:.tar=38;5;160:.taz=38;5;160:.tbz=38;5;160:.tbz2=38;5;160:.tga=38;5;170:.tgz=38;5;160:.tif=38;5;170:.tiff=38;5;170:.tlz=38;5;160:.tmp=90:.txz=38;5;160:.tz=38;5;160:.tzo=38;5;160:.tzst=38;5;160:.ucf-dist=90:.ucf-new=90:.ucf-old=90:.vob=38;5;170:.war=38;5;160:.wav=38;5;37:.webm=38;5;170:.webp=38;5;170:.wim=38;5;160:.wmv=38;5;170:.xbm=38;5;170:.xcf=38;5;170:.xpm=38;5;170:.xspf=38;5;37:.xwd=38;5;170:.xz=38;5;160:.yuv=38;5;170:.z=38;5;160:.zip=38;5;160:.zoo=38;5;160:.zst=38;5;160:~=90:bd=40;38;5;184:ca=0:cd=40;38;5;184:di=38;5;27:do=38;5;170:ex=38;5;40:ln=38;5;44:mh=0:mi=0:or=40;38;5;160:ow=38;5;19;42:pi=40;38;5;142:rs=0:sg=38;5;16;43:so=38;5;170:st=38;5;188;44:su=38;5;188;41:tw=38;5;16;42

Expected behavior

A folder with files sorted like so in a file browser

a.txt
b 1.txt
b 5.txt
b 10.txt
b 11.txt
Ssm.txt

So I'd expect the same with lsd 'natural sorting'

Actual behavior

For some reason natural sort doesn't ignore other files without any numbers in them and places a file starting with an S before a file starting with an a, which is weird

$lsd -1v
Ssm.txt
a.txt
'b 1.txt'
'b 5.txt'
'b 10.txt'
'b 11.txt'

For reference

$lsd -1
a.txt
'b 1.txt'
'b 10.txt'
'b 11.txt'
'b 5.txt'
Ssm.txt
@meain meain added the kind/bug Something isn't working label Jan 16, 2023
@juansc
Copy link
Contributor

juansc commented Mar 22, 2023

The library that provides the sorting is not active. I took a look around and none of the other crates have been maintained in the past 4 or so years. None of them have extensive tests.

What do you think of adding a version sort module as a util on this crate? I could build off of an existing crate and add more tests for the lsd usecase

@juansc juansc mentioned this issue Apr 30, 2023
5 tasks
@zwpaper
Copy link
Member

zwpaper commented Jun 29, 2023

Hi @juansc, I have checked the GNU ls, versionsort in your example works the same way in both lsd and GNU ls.

or I misunderstanding something else?

root@42b1cd5980ab:/tmp# ls -1
Ssm.txt
a.txt
'b 1.txt'
'b 10.txt'
'b 11.txt'
'b 5.txt'
root@42b1cd5980ab:/tmp# ls -1v
Ssm.txt
a.txt
'b 1.txt'
'b 5.txt'
'b 10.txt'
'b 11.txt'

@zwpaper
Copy link
Member

zwpaper commented Jun 29, 2023

cc @eugenesvk

@juansc
Copy link
Contributor

juansc commented Jun 30, 2023

Hi @zwpaper!

You are right, for this example the code behaves the same. However, the current sorting library doesn't match the GNU spec.

$ touch 'aab' 'a-b' 'a-11b' 'a-11-0' 'a-5-0.2' 'a-5-0.2b'
$ lsd -1va
.
..
a-5-0.2
a-5-0.2b
a-11-0
a-11b
a-b
aab

# Note: gls is the name of GNU ls since the ls implementation in Mac is slightly different
$ gls -1va
.
..
aab
a-5-0.2
a-5-0.2b
a-11b
a-11-0
a-b

This is because human sort prioritizes - over ascii letters. If you run it over the examples from the core utils tests, they also differ because GNU version sort gives special treatment for ~.

I'm currently in the process of breaking out the sorting code in my PR into a separate crate and I will update the PR to use the crate instead. Here's the repo so far, I'm going to go through the crate publishing process shortly.

@zwpaper
Copy link
Member

zwpaper commented Jul 1, 2023

seems great! thanks @juansc

and we may wait for your crate if you would like to create one.

/assign @juansc

@juansc
Copy link
Contributor

juansc commented Jul 2, 2023

@zwpaper the crate is published and the PR has been updated

@juansc
Copy link
Contributor

juansc commented Jul 6, 2023

#843 Has been merged. We can close out this issue on the next release

@zwpaper
Copy link
Member

zwpaper commented Jul 8, 2023

/close

@muniu-bot muniu-bot bot closed this as completed Jul 8, 2023
@muniu-bot
Copy link

muniu-bot bot commented Jul 8, 2023

@zwpaper: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants