You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add uutils/coreutils rm command into nushell #10447
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
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 coreutilsrm 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.
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.
@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
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
╰────
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.
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.
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.
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.
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.
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.
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?
Activity
kaathewisegit commentedon Sep 22, 2023
If uutils/coreutils#5304 works out, I'd want to try implementing
urm.fdncred commentedon Sep 22, 2023
@kaathewisegit I've assigned it to you. Feel free to start implementing it for a PR. Thanks for trying to make nushell better!!!
kaathewisegit commentedon Sep 24, 2023
I encountered a couple of questions I need to ask.
rmfromcoreutilsdoesn'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 thecoreutilsteams about refactoring it to return a result, where the error can be processed by Nushell.the
coreutilsrmalso doesn't support trash, while Nushell'srmdoes. I personally like this feature but its not present in GNU coreutils, so I am unsure what to do here.fdncred commentedon Sep 24, 2023
@kaathewisegit Good questions. @tertsdiepraam Do you have any advice?
tertsdiepraam commentedon Sep 24, 2023
Right, for the first question. I think it should be fine, although I'm not sure.
rmshould be refactored at some point to return asUResult, 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 forcp😄 @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.
kaathewisegit commentedon Sep 24, 2023
@tertsdiepraam, Nushell does show the output, but there is a unified style. So Nushell wraps the error in a custom
ShellErrortype and pretty-prints it, together with pointing to the command which caused it.1As 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
trashcommand could fill that role.Footnotes
wrapped
↩ucperrors look like that, for example:tertsdiepraam commentedon Sep 24, 2023
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.fdncred commentedon Sep 24, 2023
@kaathewisegit maybe when
rm --trashis 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?
tertsdiepraam commentedon Sep 24, 2023
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.fdncred commentedon Sep 24, 2023
That sounds like a decent work-around. Thanks!
3 remaining items
tertsdiepraam commentedon Sep 24, 2023
My current thinking is that we should create and expose a filename iterator, which gives files in the order that
handle_dirremoves 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.fdncred commentedon Sep 30, 2023
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
rmandmvdone by our next release if possible which is Oct 17.tertsdiepraam commentedon Sep 30, 2023
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.
sylvestre commentedon Sep 30, 2023
we can do a release when you need :)
fdncred commentedon Sep 30, 2023
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?
tertsdiepraam commentedon Sep 30, 2023
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
fdncred commentedon Sep 30, 2023
Thanks for looking into it @tertsdiepraam!
fdncred commentedon Nov 20, 2023
where are we at on uu_rm integration @kaathewisegit?
kaathewisegit commentedon Nov 20, 2023
Until uutils/coreutils#5344 lands, I don't think I can add it, since there won't be proper error handling.
fdncred commentedon Nov 20, 2023
Thanks for the update @kaathewisegit. @tertsdiepraam is there a roadblock on your PR that we can help with?
tertsdiepraam commentedon Nov 22, 2023
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.
philocalyst commentedon Apr 9, 2026
@tertsdiepraam Would find this cool :)
rmremoves write-protected files #14409 as a duplicate of this issue