derf / feh

a fast and light image viewer
https://feh.finalrewind.org
Other
1.55k stars 159 forks source link

feh should honour the current locale when sorting files #492

Open sdgn opened 4 years ago

sdgn commented 4 years ago

feh compares file and directory names using strcmp (as opposed to strcoll). This can lead to inconsistent sorting when LC_COLLATE is not set to "C" or "POSIX".

$ echo $LANG
en_US.UTF-8

$ ls -1
f1.jpg
f2.jpg
F3.jpg
F4.jpg

$ feh -L %f
./F3.jpg
./F4.jpg
./f1.jpg
./f2.jpg

$ feh --start-at f1.jpg
→ Image is displayed as [3 of 4]
derf commented 4 years ago

true; however, replacing strcmp with strcoll would lead to inconsistencies: --version-sort is implemented with strverscmp, and there is no strverscoll function available. So feh would sort images as "f1 f2 F3 F4", whereas feh --version--sort would result in "F3 F4 f1 f2".

The same applies to ls: "ls -v" does not follow the locale's sort order

Do you think locale-aware sorting by default outweighs the introduced inconsistency between feh invocations with and without --version-sort?

sdgn commented 4 years ago

I think --version-sort using strverscmp is totally fine, as it behaves like ls -v and sort -V do, today.[1]

I would only change the default case, so that strcmp_or_strverscmp becomes strcoll_or_strverscmp.

So yes, sorting "f1 f2 F3 F4" with vs. without --version-sort would yield different results, just like in the core utilities.

Should strverscmp become locale-aware at some point, feh will also benefit from that change. And if Coreutils switches to a new locale-aware version sort (which seems very unlikely), feh can – or should – switch, too.

1: The only difference is that ls and sort use Gnulib's filevercmp, which stems from Debian's dpkg and is supposed to handle file suffixes better than strverscmp.