[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FEATURE REQUEST: Re: 'ls' human-readable sizes
From: |
Pádraig Brady |
Subject: |
Re: FEATURE REQUEST: Re: 'ls' human-readable sizes |
Date: |
Sun, 18 Jun 2017 22:14:53 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
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.