colorls icon indicating copy to clipboard operation
colorls copied to clipboard

Allow sorting of files/dirs ignoring casing

Open alichtman opened this issue 5 years ago • 8 comments

Description

image

You can see in this screenshot that directories that start with a lowercase letter are sorted alphabetically, accounting for casing. There should be a flag that lets you ignore casing.

This list should be something like this:

A...
a...
B...
b...
C...
...
and so on.
  • Relevant Issues : (none)
  • Relevant PRs : (none)
  • Type of issue :
    • [ ] Installation
    • [ ] Font-related
    • [x] Feature request
    • [ ] Bug in existing feature
    • [ ] Developer mode : Code quality / Tests / Documentation

alichtman avatar Nov 05 '18 00:11 alichtman

Actually, the list is sorted according to the rules of your current locale. I am using en_US.utf8 and it is sorted like this:

$ ls -1
      abc/
      ABC/
      Badsf/
      baks/

Sorting case-insensitively was done originally, but the problem with that approach is that sorting is not deterministic, ie. you don't know whether abc will come first or ABC if you just ignore the case when sorting.

avdv avatar Nov 05 '18 08:11 avdv

you don't know whether abc will come first or ABC if you just ignore the case when sorting.

I'm okay with that. I just wanted them to be sorted together. Either order is fine.

the list is sorted according to the rules of your current locale

How should I change this in the Mac config settings? I don't see any mention of it in Preferences > Language and Region

alichtman avatar Nov 05 '18 08:11 alichtman

How should I change this in the Mac config settings? I don't see any mention of it in Preferences > Language and Region

I don't know about the Macs specifically, but the easiest thing probably is to configure this in your ~/.bashrc or ~/.zshrc:

unset LANG
export LC_COLLATE=en_US.utf8

You can run locale to see what your current settings are. The relevant setting is LC_COLLATE.

avdv avatar Nov 05 '18 08:11 avdv

image

This is what is already set.

alichtman avatar Nov 05 '18 08:11 alichtman

Seems this is broken on Macs. https://apple.stackexchange.com/questions/34054/case-insensitive-ls-sorting-in-mac-osx#81791

Some postings online suggest that the locales in BSD (and Darwin/OS X) are somewhat broken compared to those in Linux. I wrote a quick sorting program of my own which explicitly set it's locale and tested it using both the en_US.UTF-8 and C locales on my machine (Mac OS 10.6.3) and a university machine (Linux, FC11?). While sorting works as expected on the linux machine, ("a B c" vs "B a c"), the mac always sorts them as "B a c".

avdv avatar Nov 05 '18 10:11 avdv

Yep. I don't think this is fixable on my end.

alichtman avatar Nov 16 '18 12:11 alichtman

You could try LC_COLLATE=cs_CZ.ISO8859-2 colorls.

avdv avatar Nov 16 '18 14:11 avdv

That gives me exactly the behavior I want. Thanks for the help, @avdv.

alichtman avatar Nov 18 '18 09:11 alichtman