case insensitive `ls` for Catalina / APFS?

Solution 1:

If done properly the LC_COLLATE method works:

Example:

user@host ~ % export LC_COLLATE="cs_CZ.ISO8859-2" && ls -la
total 56
-rw-r--r--   1 user      staff      0 Mar  1 20:39 bin
drwx------+  4 user      staff    128 Jan 30 10:51 Desktop
drwx------+  3 user      staff     96 Oct  9 04:40 Documents
drwx------+  4 user      staff    128 Jan  4 21:11 Downloads
drwx------+ 61 user      staff   1952 Nov  2 10:29 Library
drwx------+  4 user      staff    128 Oct  9 18:17 Movies
drwx------+  3 user      staff     96 Oct  9 04:40 Music
drwx------+  5 user      staff    160 Oct 10 03:22 Pictures
drwxr-xr-x+  4 user      staff    128 Oct  9 04:40 Public
drwxr-xr-x+ 18 user      staff    576 Mar  1 20:40 .
-r--------   1 user      staff      7 Oct  9 04:43 .CFUserTextEncoding
drwxr-xr-x   3 user      staff     96 Oct 10 17:50 .config
-rw-r--r--@  1 user      staff  14340 Dec 26 22:14 .DS_Store
drwx------   6 user      staff    192 Nov 22 11:40 .ssh
drwx------   2 user      staff     64 Mar  1 20:35 .Trash
-rw-r--r--@  1 user      staff   2620 Nov 15 02:44 .zprofile
-rw-------@  1 user      staff   1544 Mar  1 20:40 .zsh_history
drwxr-xr-x   5 root      admin    160 Sep 29 22:22 ..

So simply add export LC_COLLATE="cs_CZ.ISO8859-2" to your .zprofile/.zshrc/... and restart Terminal.

If you use this locale you might experience some irregularities in shell outputs/history files etc.

Here (using mixed us_en/de_de locales im macOS) I got some irregular entries in the command history (i.e. .zsh_history) after entering German umlauts.


Probably the best idea then: create a new custom LC_COLLATE file.

Solution 2:

I agree that I wouldn't change the global LC_COLLATE. Just use it locally in your alias:

alias ls="LC_COLLATE=cs_CZ.ISO8859-2 /bin/ls"

Watch out for the undesirable effect of this particular LOCALE. Files that start with "ch", "CH", or "Ch" will be sorted between files that start with "H" and "i".

I would like to create my own custom file, I'm going to try out this: https://gist.github.com/shaunsauve/56c30ad45d1261e7164e1b32316ef7c1