coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width


From: Carl Edquist
Subject: Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width
Date: Thu, 15 Apr 2021 07:56:30 -0500 (CDT)

Hi all,

On Sun, 11 Apr 2021, Jim Meyering wrote:
> On Sat, Apr 10, 2021 at 8:22 PM Pádraig Brady wrote:
>> I really like how much more concise it makes output in general.
>
> Nice. I like this new option, too! Who would have thought :-)


Glad to hear the positive reception!  :)

Thank you for accepting the feature.


Regarding the short option, I have some thoughts for your consideration 
... but at the end of the day, of course do whatever makes sense for GNU.


> I would avoid the -W short option, as that would clash with ls from 
> FreeBSD for example.

That is a bit unfortunate about the option clash. I admit was only paying 
attention to GNU ls, where -W was, um, wide open...

If the concern is clashing with a FreeBSD ls option, maybe use -Y instead? 
(Mnemonic: 'Y' for "wide" ?)

There are only a handful of mutually-free short-option letters ...

  $ echo {a..z} {A..Z} |
    tr -d aAbBcCdDfFgGhHiIklLmnNopqQrRsStTuUvwxXZ |  # GNU ls options
    tr -d ABCDFGHILPRSTUWZabcdfghiklmnopqrstuwxy  |  # FreeBSD ls options[2]
    tr -d AaBbCcdFfghikLlMmnOoPpqRrSsTtuWwXx      |  # NetBSD  ls options[3]
    tr -d ACFHLRSTacdfghiklmnopqrstux             |  # OpenBSD ls options[4]
    tr -d ' '

  ejzEJKVY

None comes quite as naturally as -W though...

...

>From what I can tell[1][2], FreeBSD ls's -W option has to do with the 
(BSD-specific) directory whiteout entries.  It was added in the 90s, 
so I don't get the feeling there has been any desire for GNU ls to adopt 
that feature.

It just feels like a bit of a waste to retire an unused option character 
just because a BSD ls is using it for a feature that GNU doesn't seem to 
care about anyway.


And are the GNU and BSD flavors of ls really known for having compatible 
sets of option flags..?  (admittedly a rhetorical question)

For one, the other GNU -w option (--width) already clashes with FreeBSD's 
-w (raw-print non-printable chars to terminal ... AKA -N in GNU ls).  So 
maybe using -W in GNU ls for a different feature too would not be that 
out-of-character.

(In case anybody's counting, the existing -B -D -G -I -T -U -w & -Z 
options from GNU ls all clash with FreeBSD ls.  So it's already a bit of a 
jumble beyond reconciling.)


I'll also note here that for GNU ls's other sort options, the 
_super-useful_ -v (--sort=version), and even -X (--sort=extension) 
apparently never made it into the BSDs.

If FreeBSD hasn't added -X by now (which has been around in GNU ls since 
at least 1992), I imagine maybe they never will.

Anyway, maybe the BSDs just don't care to adopt cool GNU extensions, which 
is fine - but in that case maybe there's no need to hold out for them.

...

But if there is any hope to leave the door open for the possibility that 
FreeBSD ls adopts a width-sort option, with the same short-option letter 
as GNU ls, then as mentioned I might suggest '-Y'.

...

In the last case (not providing a short option at all), it might be 
entertaining/ironic if FreeBSD adopts the feature (with a short option, of 
course, as they don't have a --sort).  They either pick a letter the GNU 
ls already uses for something else (putting -W back on the table for 
GNU?), or they pick a letter that GNU ls is also not yet using, and then 
GNU can consider whether to follow suit with the letter FreeBSD picks :)


> It's probably best to not provide a short option for this at all.

Personally, I don't mind so much typing out long option names for scripts 
(they are write-once, run-many; and the long names are self-documenting 
for an unfamiliar reader).  But for interactive command line use, short 
options (as with short program names!) become a feature in themselves. 
They flow all the more effortlessly off the fingertips without penalizing 
the user for wanting to use them the fly.

If I had to type 'ls --format=long' every time I wanted to see 'ls -l', I 
suspect I would be less inclined to use it.

(Sidenote: does FreeBSD ls even _have_ long options? :)

...

Anyway, after some time if you find yourself wanting to use the feature a 
lot but being bored to type --sort=width each time, maybe that will 
provide more inclination to add a short option...

("Yes," you might say, "but that's what shell aliases are for."

But...don't you like munging short options? :)

"Search your feelings, Luke."

...

Lastly, in the help / manpage output, "width" will looks a bit lonely 
among the sort options, as the only one without an accompanying short 
option:

    --sort=WORD      sort by WORD instead of name: none (-U), size (-S),
                       time (-t), version (-v), extension (-X), width

And, it might be worth noting that in the help / manpage output, the 
_only_ documentation (although pithy) for what the different sort types 
actually do is in the description for their corresponding short options.

So, you lose the chance to document it in the --help output if you omit 
the short opiton.

...


What do you think?  :)


In any case thanks again for accepting the feature!

I look forward to using it downstream with an unpatched version of ls.


Have a nice day!

Carl


[1] https://nixdoc.net/man-pages/FreeBSD/ls.1.html
[2] https://github.com/freebsd/freebsd-src/blob/main/bin/ls/ls.c
[3] https://github.com/openbsd/src/blob/master/bin/ls/ls.c
[4] https://github.com/NetBSD/src/blob/trunk/bin/ls/ls.c


reply via email to

[Prev in Thread] Current Thread [Next in Thread]