Skip to content

add uutils/coreutils rm command into nushell #10447

Open

Description

@fdncred

Related problem

Following on the momentum of moving the uu_cp crate/command into nushell, we'd like to add the uu_rm crate/command too, as urm for now. We can use this issue to discuss parameters and other topics.

Looking for volunteers. Reply below and we can assign the issue to you.

Describe the solution you'd like

Use the ucp command code as a guide to port urm into nushell

Describe alternatives you've considered

No response

Additional context and details

No response

Activity

  1. added
    category:enhancement
    A:coreutils-uutils
    on Sep 20, 2023
  2. kaathewisegit commented on Sep 22, 2023

    @kaathewisegit
    Contributor

    If uutils/coreutils#5304 works out, I'd want to try implementing urm.

  3. fdncred commented on Sep 22, 2023

    @fdncred
    ContributorAuthor

    @kaathewisegit I've assigned it to you. Feel free to start implementing it for a PR. Thanks for trying to make nushell better!!!

  4. kaathewisegit commented on Sep 24, 2023

    @kaathewisegit
    Contributor

    I encountered a couple of questions I need to ask.

    • rm from coreutils doesn't return a result type. Instead, it prints errors to console and returns a boolean, which if true if there was an error. This approach doesn't work for Nushell, right? I think I'll have to ask the coreutils teams about refactoring it to return a result, where the error can be processed by Nushell.

    • the coreutils rm also doesn't support trash, while Nushell's rm does. I personally like this feature but its not present in GNU coreutils, so I am unsure what to do here.

  5. fdncred commented on Sep 24, 2023

    @fdncred
    ContributorAuthor

    @kaathewisegit Good questions. @tertsdiepraam Do you have any advice?

  6. tertsdiepraam commented on Sep 24, 2023

    @tertsdiepraam
    Contributor

    Right, for the first question. I think it should be fine, although I'm not sure. rm should be refactored at some point to return as UResult, but that might be difficult to do as part of this change. Feel free to give it a shot! I think nushell will show the output of printing, though? If not then I think we also might have problem for cp 😄 @fdncred knows more about that than I do.

    Trash will probably never be supported by uutils directly. At least not anytime soon, because it's not part of GNU. Let's start simple and then maybe later we can build a trash system around uutils on the nushell side.

  7. kaathewisegit commented on Sep 24, 2023

    @kaathewisegit
    Contributor

    @tertsdiepraam, Nushell does show the output, but there is a unified style. So Nushell wraps the error in a custom ShellError type and pretty-prints it, together with pointing to the command which caused it.1

    As for trash, it is purely on the side of Nushell, as You said, per the GNU spec. I will ask the maintainers about possible options, maybe adding a trash command could fill that role.

    Footnotes

    1. wrapped ucp errors look like that, for example:

      ~> ucp doesnt_exist dest
      Error: nu::shell::file_not_found
      
        × File not found
         ╭─[entry #1:1:1]
       1 │ ucp doesnt_exist dest
         ·     ──────┬─────
         ·           ╰── file not found
         ╰────
      
      ↩
  8. tertsdiepraam commented on Sep 24, 2023

    @tertsdiepraam
    Contributor

    Nushell does show the output, but there is a unified style. So Nushell wraps the error in a custom ShellError type and pretty-prints it, together with pointing to the command which caused it.

    Yeah, that's true. It gets tricky when errors for multiple files need to be shown. We won't be able to do that all using the pretty miette style, I think. However, if we start this command as a separate command from the current nushell rm, then we can build the simplest version first and then improve the integration over time.

  9. fdncred commented on Sep 24, 2023

    @fdncred
    ContributorAuthor

    @kaathewisegit maybe when rm --trash is called move the file to the trash and then call the uutils rm?

    I'm good with wrapping rm errors in ShellError. We might be able to collect all the errors and spit them out in one ShellError?

  10. tertsdiepraam commented on Sep 24, 2023

    @tertsdiepraam
    Contributor

    What we might be able to do is expose a function that removes a single file with a single error message. And then the loop would be on the nushell side and you can make every error pretty.

    @kaathewisegit are you currently working on refactoring rm? If not then I can give it a shot.

  11. fdncred commented on Sep 24, 2023

    @fdncred
    ContributorAuthor

    What we might be able to do is expose a function that removes a single file with a single error message. And then the loop would be on the nushell side and you can make every error pretty.

    That sounds like a decent work-around. Thanks!

  12. 3 remaining items

  13. tertsdiepraam commented on Sep 24, 2023

    @tertsdiepraam
    Contributor

    My current thinking is that we should create and expose a filename iterator, which gives files in the order that handle_dir removes them and then we expose a function to remove those entries. Then you'd get an iterator over results. Uutils then just prints all errors it gets and nushell can decide how to handle it, either stop on the first error, or print them all in a pretty way.

  14. fdncred commented on Sep 30, 2023

    @fdncred
    ContributorAuthor

    Any updates here? I see uutils/coreutils#5304 has landed. Or are we waiting on this "filename iterator" change by coreutils? Is there a tracking issue for that. I haven't seen it myself.

    I'm still hoping we can get rm and mv done by our next release if possible which is Oct 17.

  15. tertsdiepraam commented on Sep 30, 2023

    @tertsdiepraam
    Contributor

    I don't think we have a release planned before Oct 17. I'm not really opposed to doing another release, but I think our pace works nicely for us, so I'm not sure what the best course of action is in the long run. If it takes longer now, but we keep exposing utils, you just get more utils in 2 releases from now :) @sylvestre @cakebaker what do you think?

    As for the state here, I think the the iterator would be nice. I might find some time for it tomorrow.

  16. sylvestre commented on Sep 30, 2023

    @sylvestre
    Contributor

    we can do a release when you need :)

  17. fdncred commented on Sep 30, 2023

    @fdncred
    ContributorAuthor

    Awe, thanks @sylvestre and @tertsdiepraam ❤️.

    I'm definitely not trying to push anyone into doing a release when they don't want to, but if you're willing, that's awesome! I truly hope that you just hear my excitement about using coreutils inside of nushell, because that's all it really is. I'm just super pumped to build in whatever we can as soon as we can.

    I know there's work to be done on the coreutils side. If we can get that done and tested before our next release, that's wonderful. If we have to wait because it's not ready, (people have lives outside of opensource, of course) then we'll have to wait. Thanks so much for your willingness to help with all this.

    IIRC, we're also waiting for a permissions fix in uu_cp for our next release too. I've lost track of that but need to check in on it. Maybe it's already landed?

  18. tertsdiepraam commented on Sep 30, 2023

    @tertsdiepraam
    Contributor

    Yes, the permissions problem is being worked on here: uutils/coreutils#5261. I lost track of it too and I'll check back in there

  19. fdncred commented on Sep 30, 2023

    @fdncred
    ContributorAuthor

    Thanks for looking into it @tertsdiepraam!

  20. fdncred commented on Nov 20, 2023

    @fdncred
    ContributorAuthor

    where are we at on uu_rm integration @kaathewisegit?

  21. kaathewisegit commented on Nov 20, 2023

    @kaathewisegit
    Contributor

    Until uutils/coreutils#5344 lands, I don't think I can add it, since there won't be proper error handling.

  22. fdncred commented on Nov 20, 2023

    @fdncred
    ContributorAuthor

    Thanks for the update @kaathewisegit. @tertsdiepraam is there a roadblock on your PR that we can help with?

  23. tertsdiepraam commented on Nov 22, 2023

    @tertsdiepraam
    Contributor

    I'll have to get back to that one. Maybe start from scratch because it was getting too big. I'll reassess the situation a bit.

  24. philocalyst commented on Apr 9, 2026

    @philocalyst
    Contributor

    @tertsdiepraam Would find this cool :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A:coreutils-uutilscategory:enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions