feh icon indicating copy to clipboard operation
feh copied to clipboard

feh should honour the current locale when sorting files

Open sdgn opened this issue 6 years ago • 2 comments

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]

sdgn avatar Nov 06 '19 22:11 sdgn

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?

derf avatar Nov 07 '19 16:11 derf

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.

sdgn avatar Nov 07 '19 17:11 sdgn