Skip to content

Conversation

@WindSoilder
Copy link
Contributor

@WindSoilder WindSoilder commented Nov 21, 2024

Description

Closes: #14387
To make it happen, just need to added -l flag to du, and pass it to DirBuilder, DirInfo, FileInfo
Then tweak impl From<DirInfo> for Value and impl From<FileInfo> for Value impl.


Edit: this PR is going to:

  1. Exclude directories and files columns by default
  2. Added -l/--long flag to output directories and files columns
  3. When running du, it will output the files as well. Previously it doesn't output the size of file.

To make it happen, just need to added -r flag to du, and pass it to DirBuilder, DirInfo, FileInfo
Then tweak impl From<DirInfo> for Value and impl From<FileInfo> for Value impl.

And rename some variables.

User-Facing Changes

du is no longer output directories and file columns by default, added -r flag will show directories column, -f flag will show files column.

> du nushell
╭───┬────────────────────────────────────┬──────────┬──────────╮
 # │                path                │ apparent │ physical │
├───┼────────────────────────────────────┼──────────┼──────────┤
 0  /home/windsoilder/projects/nushell  34.6 GiB  34.7 GiB 
├───┼────────────────────────────────────┼──────────┼──────────┤
 # │                path                │ apparent │ physical │
╰───┴────────────────────────────────────┴──────────┴──────────╯
> du nushell --recursive --files # It outputs two more columns, `directories` and `files`, but the output is too long to paste here.

Tests + Formatting

Added 1 test

After Submitting

NaN

@WindSoilder WindSoilder added notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way labels Nov 21, 2024
@sholderbach sholderbach added the A:file-system Related to commands and core nushell behavior around the file system label Nov 22, 2024
@NotTheDr01ds
Copy link
Contributor

@WieeRd commented on the original request:

I personally think --recursive/-r fits better than --long/-l but either works.

Wanted to put it over here to see what others think. I can see benefits around either option, personally.

@WieeRd
Copy link

WieeRd commented Nov 22, 2024

Two reasons why I think -r/--recursive is more appropriate:

  1. -l is often used for adding extra fields to the output, showing new and more detailed information. The verbose output of du doesn't actually add anything 'new', it just recurses into child dirs and shows the exact same fields apparent and physical for the child dirs. It's a little nuanced, but I think you get what I'm trying to say.
  2. Nushell builtin commands typically try to match the flag names and roles of their original coreutils counterpart. ^du -l is already preoccupied with a flag that means something completely different. -r is not.
❯ ^du --help | rg -- '-l'
  -l, --count-links     count sizes many times if hard linked

@WindSoilder
Copy link
Contributor Author

@WieeRd Thanks, it makes sence to me. Can you provide a description text for -r flag?

@WieeRd
Copy link

WieeRd commented Nov 25, 2024

@WindSoilder I just realized a mildly inconvenient fact. I only checked ^du --help back then and only realized just now that Nushell builtin du already has a -r/--deref flag.

Find disk usage sizes of specified items.

Usage:
  > du {flags} ...(path)

Flags:
  -h, --help: Display the help message for this command
  -a, --all: Output file sizes as well as directory sizes
  -r, --deref: Dereference symlinks to their targets for size
  -x, --exclude <glob>: Exclude these file names
  -d, --max-depth <int>: Directory recursion limit
  -m, --min-size <int>: Exclude files below this size

Well this is awkward.

@WindSoilder
Copy link
Contributor Author

I think a better solution minght be: removing short flag of --deref, and adding -r/--recursive flag.

@WieeRd
Copy link

WieeRd commented Nov 26, 2024

I agree, --deref doesn't look like a flag that'll be used often to deserve a shorthand.

@WieeRd
Copy link

WieeRd commented Nov 26, 2024

I have a question about the existing flag --all which shows the size of the files in the files column.

How will/should --recursive interact with the existing --all flag?
Right now, this PR seems to automatically enable --all when --recursive (--long) is specified.

Also, two slightly off-topic complaints on the --all flag itself:

  • The files column itself is always included even when --all is not specified, which is weird.
  • --files is more fitting than --all, although renaming would cause yet another breaking change (will that matter?)

@WindSoilder
Copy link
Contributor Author

How will/should --recursive interact with the existing --all flag?
Right now, this PR seems to automatically enable --all when --recursive (--long) is specified.

I think nushell needs to treat --all and --recursive independently, if --all flag is usaged, output files column. If --recursive is usaged, outputs directories column.

--files is more fitting than --all, although renaming would cause yet another breaking change (will that matter?)

I agree with you, maybe renaming from -a(--all) to -f(--files). Anyway a breaking change is going to happen, I think it's better to break it only once

@WieeRd
Copy link

WieeRd commented Nov 27, 2024

Technically, Nushell has all the rights to make breaking changes whenever it feels like it because it is 0ver.

So in conclusion, this PR is going to:

  1. Exclude directories and files columns by default
  2. Rob the -r shorthand from --deref
  3. Add a new -r/--recursive flag, which enables the directories column (but not files)
  4. Rename -a/--all to -f/--files which enables the files column (but not directories)

Correct?

@WindSoilder
Copy link
Contributor Author

WindSoilder commented Nov 27, 2024

Yeah, in addition:

Rename -a/--all to -f/--files which enables the files column

It only enables files columns,not directories.

@WindSoilder WindSoilder changed the title add -l flag to du du: add -r/--recursive flag, rename -a/--all to -f/--file Nov 29, 2024
@fdncred
Copy link
Contributor

fdncred commented Nov 30, 2024

I'm confused by this PR. The apparent and physical totals below are all the same. What's the point of using -r for recursive and -f for files and du without any parameters if all the file totals are the same? I mean I know one has files only and one has directories only but I'm not sure how that matters. Seems like we should get rid of the -f and just have -r show both files and folders.

 du -f
╭─#──┬──────────────────────path──────────────────────┬─apparent─┬─physical─┬──────files──────╮
 0   /Users/fdncred/src/nushell/.DS_Store              6.1 KB    8.2 KB                  
 1   /Users/fdncred/src/nushell/.cargo                 1.2 KB    4.1 KB  [table 1 row]   
 2   /Users/fdncred/src/nushell/.git                  79.8 MB   92.9 MB  [table 8 rows]  
 3   /Users/fdncred/src/nushell/.gitattributes          111 B    4.1 KB                  
 4   /Users/fdncred/src/nushell/.githooks               281 B    8.2 KB  [table 2 rows]  
 5   /Users/fdncred/src/nushell/.github               40.2 KB   81.9 KB  [table 2 rows]  
 6   /Users/fdncred/src/nushell/.gitignore              660 B    4.1 KB                  
 7   /Users/fdncred/src/nushell/.mailmap               2.2 KB    4.1 KB                  
 8   /Users/fdncred/src/nushell/CITATION.cff            812 B    4.1 KB                  
 9   /Users/fdncred/src/nushell/CODE_OF_CONDUCT.md     3.4 KB    4.1 KB                  
 10  /Users/fdncred/src/nushell/CONTRIBUTING.md       11.2 KB   12.3 KB                  
 11  /Users/fdncred/src/nushell/Cargo.lock           186.4 KB  188.4 KB                  
 12  /Users/fdncred/src/nushell/Cargo.toml             9.3 KB   12.3 KB                  
 13  /Users/fdncred/src/nushell/Cross.toml              666 B    4.1 KB                  
 14  /Users/fdncred/src/nushell/LICENSE                1.1 KB    4.1 KB                  
 15  /Users/fdncred/src/nushell/README.md             12.3 KB   16.4 KB                  
 16  /Users/fdncred/src/nushell/SECURITY.md            2.7 KB    4.1 KB                  
 17  /Users/fdncred/src/nushell/assets                 1.3 MB    1.3 MB  [table 2 rows]  
 18  /Users/fdncred/src/nushell/benches               14.0 KB   20.5 KB  [table 2 rows]  
 19  /Users/fdncred/src/nushell/crates                 9.5 MB   13.2 MB  [table 1 row]   
 20  /Users/fdncred/src/nushell/devdocs               18.2 KB   28.7 KB  [table 5 rows]  
 21  /Users/fdncred/src/nushell/docker                 8.6 KB   16.4 KB  [table 3 rows]  
 22  /Users/fdncred/src/nushell/rust-toolchain.toml    1.1 KB    4.1 KB                  
 23  /Users/fdncred/src/nushell/scripts               13.6 KB   45.1 KB  [table 11 rows] 
 24  /Users/fdncred/src/nushell/src                   97.8 KB  118.8 KB  [table 10 rows] 
 25  /Users/fdncred/src/nushell/target                20.0 GB   20.3 GB  [table 2 rows]  
 26  /Users/fdncred/src/nushell/tests                687.2 KB    1.5 MB  [table 1 row]   
 27  /Users/fdncred/src/nushell/toolkit.nu            19.7 KB   20.5 KB                  
 28  /Users/fdncred/src/nushell/typos.toml              513 B    4.1 KB                  
 29  /Users/fdncred/src/nushell/wix                   24.2 KB   32.8 KB  [table 3 rows]  
╰─#──┴──────────────────────path──────────────────────┴─apparent─┴─physical─┴──────files──────╯
 du -r                                                                                                              832  08:24:44 AM
╭─#──┬──────────────────────path──────────────────────┬─apparent─┬─physical─┬───directories───╮
 0   /Users/fdncred/src/nushell/.DS_Store              6.1 KB    8.2 KB                  
 1   /Users/fdncred/src/nushell/.cargo                 1.2 KB    4.1 KB                  
 2   /Users/fdncred/src/nushell/.git                  79.8 MB   92.9 MB  [table 5 rows]  
 3   /Users/fdncred/src/nushell/.gitattributes          111 B    4.1 KB                  
 4   /Users/fdncred/src/nushell/.githooks               281 B    8.2 KB                  
 5   /Users/fdncred/src/nushell/.github               40.2 KB   81.9 KB  [table 3 rows]  
 6   /Users/fdncred/src/nushell/.gitignore              660 B    4.1 KB                  
 7   /Users/fdncred/src/nushell/.mailmap               2.2 KB    4.1 KB                  
 8   /Users/fdncred/src/nushell/CITATION.cff            812 B    4.1 KB                  
 9   /Users/fdncred/src/nushell/CODE_OF_CONDUCT.md     3.4 KB    4.1 KB                  
 10  /Users/fdncred/src/nushell/CONTRIBUTING.md       11.2 KB   12.3 KB                  
 11  /Users/fdncred/src/nushell/Cargo.lock           186.4 KB  188.4 KB                  
 12  /Users/fdncred/src/nushell/Cargo.toml             9.3 KB   12.3 KB                  
 13  /Users/fdncred/src/nushell/Cross.toml              666 B    4.1 KB                  
 14  /Users/fdncred/src/nushell/LICENSE                1.1 KB    4.1 KB                  
 15  /Users/fdncred/src/nushell/README.md             12.3 KB   16.4 KB                  
 16  /Users/fdncred/src/nushell/SECURITY.md            2.7 KB    4.1 KB                  
 17  /Users/fdncred/src/nushell/assets                 1.3 MB    1.3 MB  [table 1 row]   
 18  /Users/fdncred/src/nushell/benches               14.0 KB   20.5 KB                  
 19  /Users/fdncred/src/nushell/crates                 9.5 MB   13.2 MB  [table 39 rows] 
 20  /Users/fdncred/src/nushell/devdocs               18.2 KB   28.7 KB                  
 21  /Users/fdncred/src/nushell/docker                 8.6 KB   16.4 KB                  
 22  /Users/fdncred/src/nushell/rust-toolchain.toml    1.1 KB    4.1 KB                  
 23  /Users/fdncred/src/nushell/scripts               13.6 KB   45.1 KB                  
 24  /Users/fdncred/src/nushell/src                   97.8 KB  118.8 KB                  
 25  /Users/fdncred/src/nushell/target                20.0 GB   20.3 GB  [table 4 rows]  
 26  /Users/fdncred/src/nushell/tests                687.2 KB    1.5 MB  [table 14 rows] 
 27  /Users/fdncred/src/nushell/toolkit.nu            19.7 KB   20.5 KB                  
 28  /Users/fdncred/src/nushell/typos.toml              513 B    4.1 KB                  
 29  /Users/fdncred/src/nushell/wix                   24.2 KB   32.8 KB                  
╰─#──┴──────────────────────path──────────────────────┴─apparent─┴─physical─┴───directories───╯
 du                                                                                                                 519  08:25:10 AM
╭─#──┬──────────────────────path──────────────────────┬─apparent─┬─physical─╮
 0   /Users/fdncred/src/nushell/.DS_Store              6.1 KB    8.2 KB 
 1   /Users/fdncred/src/nushell/.cargo                 1.2 KB    4.1 KB 
 2   /Users/fdncred/src/nushell/.git                  79.8 MB   92.9 MB 
 3   /Users/fdncred/src/nushell/.gitattributes          111 B    4.1 KB 
 4   /Users/fdncred/src/nushell/.githooks               281 B    8.2 KB 
 5   /Users/fdncred/src/nushell/.github               40.2 KB   81.9 KB 
 6   /Users/fdncred/src/nushell/.gitignore              660 B    4.1 KB 
 7   /Users/fdncred/src/nushell/.mailmap               2.2 KB    4.1 KB 
 8   /Users/fdncred/src/nushell/CITATION.cff            812 B    4.1 KB 
 9   /Users/fdncred/src/nushell/CODE_OF_CONDUCT.md     3.4 KB    4.1 KB 
 10  /Users/fdncred/src/nushell/CONTRIBUTING.md       11.2 KB   12.3 KB 
 11  /Users/fdncred/src/nushell/Cargo.lock           186.4 KB  188.4 KB 
 12  /Users/fdncred/src/nushell/Cargo.toml             9.3 KB   12.3 KB 
 13  /Users/fdncred/src/nushell/Cross.toml              666 B    4.1 KB 
 14  /Users/fdncred/src/nushell/LICENSE                1.1 KB    4.1 KB 
 15  /Users/fdncred/src/nushell/README.md             12.3 KB   16.4 KB 
 16  /Users/fdncred/src/nushell/SECURITY.md            2.7 KB    4.1 KB 
 17  /Users/fdncred/src/nushell/assets                 1.3 MB    1.3 MB 
 18  /Users/fdncred/src/nushell/benches               14.0 KB   20.5 KB 
 19  /Users/fdncred/src/nushell/crates                 9.5 MB   13.2 MB 
 20  /Users/fdncred/src/nushell/devdocs               18.2 KB   28.7 KB 
 21  /Users/fdncred/src/nushell/docker                 8.6 KB   16.4 KB 
 22  /Users/fdncred/src/nushell/rust-toolchain.toml    1.1 KB    4.1 KB 
 23  /Users/fdncred/src/nushell/scripts               13.6 KB   45.1 KB 
 24  /Users/fdncred/src/nushell/src                   97.8 KB  118.8 KB 
 25  /Users/fdncred/src/nushell/target                20.0 GB   20.2 GB 
 26  /Users/fdncred/src/nushell/tests                687.2 KB    1.5 MB 
 27  /Users/fdncred/src/nushell/toolkit.nu            19.7 KB   20.5 KB 
 28  /Users/fdncred/src/nushell/typos.toml              513 B    4.1 KB 
 29  /Users/fdncred/src/nushell/wix                   24.2 KB   32.8 KB 
╰─#──┴──────────────────────path──────────────────────┴─apparent─┴─physical─╯

I agree that its' better to let du without parameters just do a summary and not include the details column.

@WindSoilder
Copy link
Contributor Author

I agree, actually I'm not really sure what -f/--files mean

@fdncred
Copy link
Contributor

fdncred commented Dec 4, 2024

My suggestion is to have du just print out path,apparent,physical columns and du --long print out path,apparent,physical,files,directories columns

@NotTheDr01ds
Copy link
Contributor

@fdncred Funny, that was my original request that led to this ;-).

I waffle on the --recursive vs. --long, but given the confusion with --recursive, I'm more inclined to think --long is the correct terminology here.

It's really just adding two more columns, like we do with ls --long. The side-effect is that, since those columns are nested, it turns out to be a recursive operation, but that's a side-effect. The actual behavior is --long.

@WieeRd
Copy link

WieeRd commented Dec 4, 2024

Perhaps we can even remove the distinction between directories and files column.
Merge them into single items column and instead add a new type column that indicates the type of the entry.
It'll become very similar to ls -d **/*, but focused on disk usage and retaining the directory structure.

@fdncred
Copy link
Contributor

fdncred commented Dec 10, 2024

@WindSoilder Are you going to have time to update this?

@WindSoilder WindSoilder changed the title du: add -r/--recursive flag, rename -a/--all to -f/--file du: add -l/--long flag, remove -a/--all flag Dec 10, 2024
@WindSoilder
Copy link
Contributor Author

@fdncred Sorry, I almost forget it. I have updated the pr to follow your suggestion: #14407 (comment)

@fdncred
Copy link
Contributor

fdncred commented Dec 10, 2024

I'm not sure this is any better or worse. It's kind of a mixed bag. It would be nice to have some progress indication. If you're in any directory with substance, it looks like it just hangs when it's actually counting things. I'm fine with moving forward with this though.

@fdncred fdncred merged commit dff6268 into nushell:main Dec 10, 2024
14 checks passed
@github-actions github-actions bot added this to the v0.101.0 milestone Dec 10, 2024
fdncred pushed a commit that referenced this pull request Dec 18, 2024
Just noticed that I forget to remove `-a/-all` flag in `du`'s signature
in #14407

This pr is going to remove it
@WindSoilder WindSoilder deleted the du_l branch December 23, 2024 13:41
@WindSoilder WindSoilder mentioned this pull request Dec 23, 2024
WindSoilder added a commit that referenced this pull request Dec 25, 2024
# Description
Following up for issue comment:
#14407 (comment)

> it looks like it just hangs when it's actually counting things

I noticed that `du` command collects output internally, so it doesn't
streaming.

This pr is trying to make it streaming

# User-Facing Changes
NaN

# Tests + Formatting
NaN
mrkkrp added a commit to mrkkrp/nixos-config that referenced this pull request Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:file-system Related to commands and core nushell behavior around the file system deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make du output more concise by default

5 participants