Re: FEATURE REQUEST: Re: 'ls' human-readable sizes

2017-06-19 Thread Pádraig Brady
On 18/06/17 23:04, Boruch Baum wrote:
> On 2017-06-18 22:14, Pádraig Brady wrote:
>> On 18/06/17 19:02, Boruch Baum wrote:
>>> On 2017-06-18 11:32, Pádraig Brady wrote:
 On 18/06/17 03:51, Boruch Baum wrote:
> 
> [snip]
>>> want to use it for your option (eg. `--format='%f €' ). Even if you
> Hmm, this was supposed to be a 'euro currency sign'.  ^^
> 
> [snip]
> 
>>> 2.1] The current `h' doesn't note the units of small-sized files as
>>> `bytes', so let it do so, but instead of marking those numbers with a
>>> `B', use a space (a kind of "silent" `b', like in "lamb").
>>
>> You mean, a kind of "silent" `b', like in "subtle" :)
>>
>>> The result
>>> would align all numbers in the column, and it would be easier to note
>>> the `K', `M', etc. markers. This suggestion produces the same result
>>> as indentation, but is just a tweak to the already existing `h' for
>>> small values.
>>
>> This isn't a bad suggestion.
>> A 1 minute patch not considering edge cases to do that is:
> 
> [snip]
> 
>> Which results in this output:
>>
>> drwxrwxr-x. 26 padraig padraig 4.0K Jun 17 19:50 tests
>> -r--r--r--.  1 padraig padraig  48K Mar  8 21:02 THANKS
>> -rwxrwxr-x.  1 padraig padraig 441  May 28  2012 thanks-gen
>> -rw-rw-r--.  1 padraig padraig  38K Mar 11 10:44 THANKS.in
>> -rw-rw-r--.  1 padraig padraig 2.0K Mar  9 23:07 THANKS-to-translators
>> -rw-rw-r--.  1 padraig padraig 121  Aug 23  2011 THANKStt.in
>> -rw-rw-r--.  1 padraig padraig 6.7K Jan  1 14:34 TODO
>>
>> Not to everyone's taste I suppose being not right aligned.
> 
> I'll vote thumbs up, since it's optional

True, but -h would be a very commonly used option.
I'd be 60:40 against this change.

> but it occurs to me to ask,
> without knowing the `ls' internals: does this mess up or complicate
> sorting by size?

No, that's not impacted as done numerically before output.

>>> 2.2] Does LS_COLORS operate only on the final field? Is there a
>>> possible user hack to have LS_COLORS operate on the size field?
>>
>> Not at present. You might be able to do some post processing highlighting
>> like my http://www.pixelbeat.org/scripts/l script does.
> 
> I'll check it out, thanks.

An example implementation is at
https://gist.github.com/anonymous/327fa19405883157ae660236cbc9ad5e

cheers,
Pádraig




Re: FEATURE REQUEST: Re: 'ls' human-readable sizes

2017-06-19 Thread Boruch Baum
On 2017-06-18 22:14, Pádraig Brady wrote:
> On 18/06/17 19:02, Boruch Baum wrote:
> > On 2017-06-18 11:32, Pádraig Brady wrote:
> >> On 18/06/17 03:51, Boruch Baum wrote:

[snip]
> > want to use it for your option (eg. `--format='%f €' ). Even if you
Hmm, this was supposed to be a 'euro currency sign'.  ^^

[snip]

> > 2.1] The current `h' doesn't note the units of small-sized files as
> > `bytes', so let it do so, but instead of marking those numbers with a
> > `B', use a space (a kind of "silent" `b', like in "lamb").
>
> You mean, a kind of "silent" `b', like in "subtle" :)
>
> > The result
> > would align all numbers in the column, and it would be easier to note
> > the `K', `M', etc. markers. This suggestion produces the same result
> > as indentation, but is just a tweak to the already existing `h' for
> > small values.
>
> This isn't a bad suggestion.
> A 1 minute patch not considering edge cases to do that is:

[snip]

> Which results in this output:
>
> drwxrwxr-x. 26 padraig padraig 4.0K Jun 17 19:50 tests
> -r--r--r--.  1 padraig padraig  48K Mar  8 21:02 THANKS
> -rwxrwxr-x.  1 padraig padraig 441  May 28  2012 thanks-gen
> -rw-rw-r--.  1 padraig padraig  38K Mar 11 10:44 THANKS.in
> -rw-rw-r--.  1 padraig padraig 2.0K Mar  9 23:07 THANKS-to-translators
> -rw-rw-r--.  1 padraig padraig 121  Aug 23  2011 THANKStt.in
> -rw-rw-r--.  1 padraig padraig 6.7K Jan  1 14:34 TODO
>
> Not to everyone's taste I suppose being not right aligned.

I'll vote thumbs up, since it's optional, but it occurs to me to ask,
without knowing the `ls' internals: does this mess up or complicate
sorting by size?

> > 2.2] Does LS_COLORS operate only on the final field? Is there a
> > possible user hack to have LS_COLORS operate on the size field?
>
> Not at present. You might be able to do some post processing highlighting
> like my http://www.pixelbeat.org/scripts/l script does.

I'll check it out, thanks.

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0



Re: FEATURE REQUEST: Re: 'ls' human-readable sizes

2017-06-18 Thread Pádraig Brady
On 18/06/17 19:02, Boruch Baum wrote:
> On 2017-06-18 11:32, Pádraig Brady wrote:
>> On 18/06/17 03:51, Boruch Baum wrote:
>>> When I visually scan 'ls -lh' output, I find it difficult to notice
>>> every instance of the convenience presentation of 'k' and 'm'. Could
>>> you consider making them more visible, either through colorization of the 
>>> letter,
>>> bold face of the letter, indentation, or marking?
>>>
>>> By indentation, I mean comething like:
>>>
>>>111
>>>  4M
>>> 11
>>>
>>> By marking, I mean something like:
>>>
>>>111
>>> 4M<-
>>> 11
>>
>> This wouldn't be core functionality so if we were to do that
>> it would be better in numfmt I think. For example you can get ls -lh
>> functionality now with numfmt like:
>>
>>   \ls -l | numfmt --header --field=5 --to=si
>>
>> Looking at my numfmt TODO here I see this pertinent item:
>>
>>   Have numfmt --format='%f ' put a space between number and auto units
> 
> Thanks for the quick reply.
> 
> 1] For the `numfmt' functionality, let me suggest that your TODO item
> alter the implementation.
> 
> 1.1] Using spaces for purposes other than for delimiting in `numfmt'
> is bound to mess up scripts. How about using an underscore instead of
> a space?
> 
> 1.2] My guess is that people would want / expect "post number" text,
> including whitespace, to appear exactly as they write it. For example
> they might actually want a space in their format string exactly where
> you want to use it for your option (eg. `--format='%f €' ). Even if you
> reject the idea in par. 1.1, maybe use. `--format='%_f' to indicate
> placement of the space (or my preference, the underscore).

Right 1.2 is getting to my core idea for numfmt,
i.e. that it would center around the --format argument much like you describe 
here.

> 2] By way of persisting about an enhancement to `ls' functionality:
> 
> 2.1] The current `h' doesn't note the units of small-sized files as
> `bytes', so let it do so, but instead of marking those numbers with a
> `B', use a space (a kind of "silent" `b', like in "lamb").

You mean, a kind of "silent" `b', like in "subtle" :)

> The result
> would align all numbers in the column, and it would be easier to note
> the `K', `M', etc. markers. This suggestion produces the same result
> as indentation, but is just a tweak to the already existing `h' for
> small values.

This isn't a bad suggestion.
A 1 minute patch not considering edge cases to do that is:

diff --git a/src/ls.c b/src/ls.c
index 4802d92..746d3ed 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -4071,12 +4071,18 @@ print_long_format (const struct fileinfo *f)
  : human_readable (unsigned_file_size (f->stat.st_size),
hbuf, file_human_output_opts, 1,
file_output_block_size));
-  int pad;
-  for (pad = file_size_width - mbswidth (size, 0); 0 < pad; pad--)
+  int curr_size_width = mbswidth (size, 0);
+  int pad = file_size_width - curr_size_width;
+  size_t size_len = strlen (size);
+  if (pad && ISDIGIT (size[size_len - 1]))
+pad--;
+  for (; 0 < pad; pad--)
 *p++ = ' ';
   while ((*p++ = *size++))
 continue;
   p[-1] = ' ';
+  if (ISDIGIT (size[-2]))
+*p++ = ' ';
 }

Which results in this output:

drwxrwxr-x. 26 padraig padraig 4.0K Jun 17 19:50 tests
-r--r--r--.  1 padraig padraig  48K Mar  8 21:02 THANKS
-rwxrwxr-x.  1 padraig padraig 441  May 28  2012 thanks-gen
-rw-rw-r--.  1 padraig padraig  38K Mar 11 10:44 THANKS.in
-rw-rw-r--.  1 padraig padraig 2.0K Mar  9 23:07 THANKS-to-translators
-rw-rw-r--.  1 padraig padraig 121  Aug 23  2011 THANKStt.in
-rw-rw-r--.  1 padraig padraig 6.7K Jan  1 14:34 TODO

Not to everyone's taste I suppose being not right aligned.

> 2.2] Does LS_COLORS operate only on the final field? Is there a
> possible user hack to have LS_COLORS operate on the size field?

Not at present. You might be able to do some post processing highlighting
like my http://www.pixelbeat.org/scripts/l script does.

cheers,
Pádraig.



Re: FEATURE REQUEST: Re: 'ls' human-readable sizes

2017-06-18 Thread L A Walsh

Pádraig Brady wrote:

On 18/06/17 03:51, Boruch Baum wrote:
  

When I visually scan 'ls -lh' output, I find it difficult to notice
every instance of the convenience presentation of 'k' and 'm'. Could
you consider making them more visible, either through colorization of the 
letter,
bold face of the letter, indentation, or marking?



This wouldn't be core functionality

---
   Whereas putting quotes around filenames is core functionality?

   Maybe an ENV option, like LS_OPTIONS could be provided
to allow specifying interactive options like the filename
quoting that wouldn't be active when scripts are run?





Re: FEATURE REQUEST: Re: 'ls' human-readable sizes

2017-06-18 Thread Pádraig Brady
On 18/06/17 03:51, Boruch Baum wrote:
> When I visually scan 'ls -lh' output, I find it difficult to notice
> every instance of the convenience presentation of 'k' and 'm'. Could
> you consider making them more visible, either through colorization of the 
> letter,
> bold face of the letter, indentation, or marking?
> 
> By indentation, I mean comething like:
> 
>111
>  4M
> 11
> 
> By marking, I mean something like:
> 
>111
> 4M<-
> 11

This wouldn't be core functionality so if we were to do that
it would be better in numfmt I think. For example you can get ls -lh
functionality now with numfmt like:

  \ls -l | numfmt --header --field=5 --to=si

Looking at my numfmt TODO here I see this pertinent item:

  Have numfmt --format='%f ' put a space between number and auto units

cheers,
Pádraig