lsd icon indicating copy to clipboard operation
lsd copied to clipboard

Add IEC and SI units/unit prefixes

Open gryffyn opened this issue 1 year ago • 15 comments

lsd currently uses IEC units, but SI prefixes. This PR adds two values to the --size flag and the associated config file entry.

  • --size iec uses IEC units and IEC prefixes (KiB, MiB, etc.)
  • --size si uses SI units and SI prefixes (KB, MB, etc.)

A 4,000,000 byte would thus be represented as:

  • 3.8 MB with --size default
  • 3.8 MiB with --size iec
  • 4.0 MB with --size si

TODO

  • [x] Use cargo fmt
  • [ ] Add necessary tests
  • [x] Add changelog entry
  • [x] Update default config/theme in README (if applicable)
  • [x] Update man page at lsd/doc/lsd.md (if applicable)

gryffyn avatar Mar 26 '23 04:03 gryffyn

The currents unit tests in src/meta/size.rs use IEC units (1024) for checking size.value_string() and I'm unsure whether I need to write tests that use SI (1000) for checking the value. If not, adding tests can be marked as done.

gryffyn avatar Mar 26 '23 04:03 gryffyn

Shouldn't the i in binary prefixes be lower case? So KiB, MiB, ... instead of KIB, MIB, ... Wikipedia

frankebel avatar Aug 28 '23 11:08 frankebel

Yes they should, I'll fix this when I get back to my computer.

gryffyn avatar Sep 01 '23 17:09 gryffyn

The constants use uppercase to comply with rust's naming scheme, but the actual strings are in the correct mixed case.

gryffyn avatar Sep 09 '23 02:09 gryffyn

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gryffyn

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

muniu-bot[bot] avatar Sep 12 '23 02:09 muniu-bot[bot]

I've added the --si flag and the comment about the Rust naming.

gryffyn avatar Sep 12 '23 03:09 gryffyn

Hi @gryffyn --si is enough, and it should not be used with the --size flag, --size should be able to cowork with the --si flag.

so please help with the following:

  1. revert the --size changes
  2. add docs for --si
  3. fix merge conflict

zwpaper avatar Sep 12 '23 04:09 zwpaper

Forgot about the docs, will update them and fix the merge conflict.

Which --size changes should I revert? Do you mean that--si should be its own flag, and --size should have the options default, short, iec, si, bytes, or that --si should be the only flag that controls toggling SI units and --size should have the options default, short, bytes?

gryffyn avatar Sep 12 '23 04:09 gryffyn

that --si should be the only flag that controls toggling SI units and --size should have the options default, short, bytes?

I prefer this one, so that --si could be used with --size

zwpaper avatar Sep 13 '23 00:09 zwpaper

The issue then is that there's currently three "modes". lsd's default is IEC units and SI prefixes. Adding the --si flag adds the ability to use SI units and prefixes, but this still leaves out IEC units and prefixes. Should I add an --iec flag that does the same thing as --si but for IEC units instead of SI?

gryffyn avatar Sep 13 '23 04:09 gryffyn

I have checked the GNU ls, it is not adding the B suffix for both iec and si format, maybe we can learn from it, only use one character to represent the unit for both iec and si, like:

also, we can drop the space between number and unit to make size as only one block

.rw-r-----. root    root      11K Mon Sep 11 16:25:41 2023  kdump.log
.rw-rw-r--. root    root     245G Thu Sep 14 09:40:09 2023  lastlog
.rw-------  root    root        5 Mon Sep 11 17:12:01 2023  maillog

zwpaper avatar Sep 14 '23 01:09 zwpaper

To what extent do you want to just replicate ls and how opinionated do you want to be? Because I would argue that a "modern" ls replacement should go the same way as various DEs and distros and adopt the the IEC recommendations entirely. Making binary rather than metric default, as it is in ls, is fine by me, but I think the use of binary units should be then clearly flagged to the user by using the binary prefixes. The --si option can then give the SI prefixes. But I think mixing the SI prefixes with the binary unit is a bad idea, it goes against both modern convention and international agreement, leads to further confusion on the topic, and is only really still used by Windows.

I also, as a scientist, very much support the current style of the size in lsd, with a space between value and unit and the additional B, as it is the correct way to do it per the SI. Personally, I also find it much more aesthetically pleasing. I would view this as a positive upgrade over traditional ls.

matterhorn103 avatar Nov 06 '23 14:11 matterhorn103

hi @matterhorn103, thanks for your options. every opensource project needs a principle to drive the development, as for lsd, we try to align with the GNU ls, that's why I was discussing that.

as this could have some more discussion, I am deferring this PR to the Next release, so we can do more discussion.

as for the current output format it has worked for years, I am ok to keep it unchanged.

but we have to involve a break change for the prefix and unit, as for keeping GNU ls compatibility, I prefer the iec prefix and unit by default, and --si change both.

what is your idea? @gryffyn

zwpaper avatar Dec 21 '23 06:12 zwpaper

I understand that aligning with GNU ls is a primary goal :)

I like your suggestion @zwpaper: that the lsd default changes to become the same as with a new --iec flag, with both IEC prefixes and units, and a new --si flag gives SI prefixes and units. That's the simplest solution that is both "correct" and aligns to ls.

(Aligns in that it gives the same numbers, anyway – the fact that the formatting is slightly different seems fine to me, since nicer/better formatting is basically what lsd is for, right?)

To follow the example of @gryffyn

A 4,000,000 byte would thus be represented as:

  • 3.8 MiB by default
  • 3.8 MiB with --iec
  • 4.0 MB with --si

matterhorn103 avatar Jan 10 '24 22:01 matterhorn103

I agree with @matterhorn103 and @zwpaper, using IEC units and prefixes as default and having SI units/prefixes behind a flag would work well.

I'll rework this PR soon to reflect that.

gryffyn avatar Jan 10 '24 22:01 gryffyn