colorls
colorls copied to clipboard
Allow sorting of files/dirs ignoring casing
Description
![image](https://user-images.githubusercontent.com/20600565/47972211-ac2dd580-e05f-11e8-96a6-076488071b41.png)
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
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.
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
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.
![image](https://user-images.githubusercontent.com/20600565/47987755-f9349a80-e0a5-11e8-92f8-18aadb97a4d5.png)
This is what is already set.
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".
Yep. I don't think this is fixable on my end.
You could try LC_COLLATE=cs_CZ.ISO8859-2 colorls
.
That gives me exactly the behavior I want. Thanks for the help, @avdv.