2
3
Fork
You've already forked ncsu
0

Add ability to move files to trash instead of permanently deleting them #215

Closed
opened 2022年12月02日 09:10:38 +01:00 by SUPERCILEX · 11 comments
SUPERCILEX commented 2022年12月02日 09:10:38 +01:00 (Migrated from code.blicky.net)
Copy link

Permanently deleting stuff is scary, so it'd be nice to be able to move things to the trash first.

I think this could also close https://code.blicky.net/yorhel/ncdu/issues/149 since moves are instant.

Permanently deleting stuff is scary, so it'd be nice to be able to move things to the trash first. I think this could also close https://code.blicky.net/yorhel/ncdu/issues/149 since moves are instant.
5m1th commented 2023年08月30日 07:45:52 +02:00 (Migrated from code.blicky.net)
Copy link

I would also really appreciate that feature!
Maybe https://github.com/andreafrancia/trash-cli could be utilised.

I would also really appreciate that feature! Maybe https://github.com/andreafrancia/trash-cli could be utilised.
hb commented 2024年01月31日 22:36:34 +01:00 (Migrated from code.blicky.net)
Copy link

Coming here for this feature request too. Similar to @5m1th , I'd like to suggest having an CLI option to use a custom delete function that the built-in deleteItem() one that is executed when a file/folder is deleted. I think it would be sufficient to do a system call.

Here's what CLI for this could look like;

$ ncdu --delete-by="rm -rf"
$ ncdu --delete-by="trash-put"

In Bash terms, the internal system call would correspond to calling rm -rf "$@" and trash-put "$@", respectively.

PS. I'm coming to this from trying to remove as much friction as possible for rookie HPC users. If they have to wait minutes to wipe large folders, they might procrastinate it. By having a snappy delete options, like trash-put, for ncdu increases the chances for users cleaning up files.

Coming here for this feature request too. Similar to @5m1th , I'd like to suggest having an CLI option to use a custom delete function that [the built-in `deleteItem()` one](https://code.blicky.net/yorhel/ncdu/src/commit/491988d9a5e84964b4963375080777248f3ad34f/src/delete.zig#L41-L68) that is executed when a file/folder is deleted. I think it would be sufficient to do a system call. Here's what CLI for this could look like; ```sh $ ncdu --delete-by="rm -rf" $ ncdu --delete-by="trash-put" ``` In Bash terms, the internal system call would correspond to calling `rm -rf "$@"` and `trash-put "$@"`, respectively. PS. I'm coming to this from trying to remove as much friction as possible for rookie HPC users. If they have to wait minutes to wipe large folders, they might procrastinate it. By having a snappy delete options, like `trash-put`, for `ncdu` increases the chances for users cleaning up files.
5m1th commented 2024年02月01日 15:00:22 +01:00 (Migrated from code.blicky.net)
Copy link

I agree with @hb.
Or even just the built-in gio trash, that I only recently learnt about: https://man.archlinux.org/man/gio.1

I agree with @hb. Or even just the built-in `gio trash`, that I only recently learnt about: https://man.archlinux.org/man/gio.1
ivanstepanovftw commented 2025年07月09日 18:57:59 +02:00 (Migrated from code.blicky.net)
Copy link

I have accidentally deleted game with saves with no way to restore it 😆

What about this?

┌───Confirm delete─────────────────────────────────────────┐
│ Are you sure you want to delete "zig-spi...st-executor" │
│ and all of its contents? │
│ │
│ delete trash no always trash always delete │
└──────────────────────────────────────────────────────────┘

This is even better and safer from misclick when selecting "no"

I have accidentally deleted game with saves with no way to restore it 😆 What about this? ``` ┌───Confirm delete─────────────────────────────────────────┐ │ Are you sure you want to delete "zig-spi...st-executor" │ │ and all of its contents? │ │ │ │ delete trash no always trash always delete │ └──────────────────────────────────────────────────────────┘ ``` This is even better and safer from misclick when selecting "no"
yorhel commented 2025年07月10日 08:59:33 +02:00 (Migrated from code.blicky.net)
Copy link

Closing this in favor of #165.

Closing this in favor of #165.
hb commented 2025年07月10日 12:37:06 +02:00 (Migrated from code.blicky.net)
Copy link

@yorhel wrote in https://code.blicky.net/yorhel/ncdu/issues/215#issuecomment-1752:

Closing this in favor of #165.

TL;DR: Please reconsider - the "select-files" and "move-to-trash" features are complementary of each other, not supplementary.

I see how the feature request in #165 can be used to emulate "moving to trash", but I'd like to argue it does not give the end-user (think rookie users) that same powers as ncdu currently does for removing files. One of the advantages of ncdu is that the user can interactively walk through folders and remove files and folders right there and then. The "select files and return" approach comes with much more friction, e.g. if you want to iteratively move files to trash, find some more, and so on, then you need a wrapper tool around ncdu that emulates such a user experience. Also, the move-to-trash feature suggested here comes with the same UX benefit as ncdu's current delete feature - the files listed disappear as they are deleted. This way makes the overview of your files and folder smaller and smaller as you try to clean up a huge directory structure. Selecting files will not do that for you. Again, think of rookie users that sysadmins beg to clean up their HOME folders. I've seen this in every multi-user environments I've been part of. I such cases we need to minimize friction as far as possible. I think ncdu is in a great position to do this and there will be tons of grateful sysadms and end-users out there.

@yorhel wrote in https://code.blicky.net/yorhel/ncdu/issues/215#issuecomment-1752: > Closing this in favor of #165. TL;DR: Please reconsider - the "select-files" and "move-to-trash" features are complementary of each other, not supplementary. I see how the feature request in #165 can be used to emulate "moving to trash", but I'd like to argue it does not give the end-user (think rookie users) that same powers as `ncdu` currently does for removing files. One of the advantages of `ncdu` is that the user can interactively walk through folders and remove files and folders right there and then. The "select files and return" approach comes with much more friction, e.g. if you want to iteratively move files to trash, find some more, and so on, then you need a wrapper tool around `ncdu` that emulates such a user experience. Also, the move-to-trash feature suggested here comes with the same UX benefit as ncdu's current delete feature - the files listed disappear as they are deleted. This way makes the overview of your files and folder smaller and smaller as you try to clean up a huge directory structure. Selecting files will not do that for you. Again, think of rookie users that sysadmins beg to clean up their HOME folders. I've seen this in every multi-user environments I've been part of. I such cases we need to minimize friction as far as possible. I think ncdu is in a great position to do this and there will be tons of grateful sysadms and end-users out there.
ivanstepanovftw commented 2025年07月10日 14:36:15 +02:00 (Migrated from code.blicky.net)
Copy link

^ this.

Imagine ncdu outputs zstd compressed text file of paths you selected to "delete" separated by newline.
Or when ssh connection closed - you will lost all your "selected" files.

if you want to iteratively move files to trash, find some more, and so on, then you need a wrapper tool around ncdu that emulates such a user experience.

I was thinking about this tool, but didn't want to risk because of rejection and I was right to be aware of impulsiveness. It also requires a datetime library that is not in Zig std yet. Dependency on datetime library will also lead to rejection, of course.

Please re-open.

@hb what do you think about #265 approach? I want to hear your feedback.

^ this. Imagine ncdu outputs zstd compressed text file of paths you selected to "delete" separated by newline. Or when ssh connection closed - you will lost all your "selected" files. > if you want to iteratively move files to trash, find some more, and so on, then you need a wrapper tool around ncdu that emulates such a user experience. I was thinking about this tool, but didn't want to risk because of rejection and I was right to be aware of impulsiveness. It also requires a datetime library that is not in Zig std yet. Dependency on datetime library will also lead to rejection, of course. Please re-open. @hb what do you think about #265 approach? I want to hear your feedback.
yorhel commented 2025年07月10日 16:40:28 +02:00 (Migrated from code.blicky.net)
Copy link

Hmm, as an alternative, would a --delete-command="rm -ri"-like option work? That will change the behavior of 'd' to call the given command instead of using the built-in delete functionality. Command will be executed in the same way as NCDU_SHELL currently works, so it can support interactivity and/or provide its own progress indicators. On completion, ncdu will re-scan the selected item and remove it from the in-memory tree if "deletion" was a success.

@ivanstepanovftw I'm not interested in PRs at the moment (nor in general, actually)

Hmm, as an alternative, would a `--delete-command="rm -ri"`-like option work? That will change the behavior of 'd' to call the given command instead of using the built-in delete functionality. Command will be executed in the same way as NCDU_SHELL currently works, so it can support interactivity and/or provide its own progress indicators. On completion, ncdu will re-scan the selected item and remove it from the in-memory tree if "deletion" was a success. @ivanstepanovftw I'm not interested in PRs at the moment ([nor in general](https://dev.yorhel.nl/contributing), actually)
hb commented 2025年07月10日 18:35:00 +02:00 (Migrated from code.blicky.net)
Copy link

... would a --delete-command="rm -ri"-like option work?

For me, yes; https://code.blicky.net/yorhel/ncdu/issues/215#issuecomment-1498

The rest of your ideas SGTM. Thx

> ... would a --delete-command="rm -ri"-like option work? For me, yes; https://code.blicky.net/yorhel/ncdu/issues/215#issuecomment-1498 The rest of your ideas SGTM. Thx
yorhel commented 2025年07月10日 21:30:26 +02:00 (Migrated from code.blicky.net)
Copy link

Lol, I vaguely remember seeing the idea float around before, didn't realize it was from you in this very thread.

Lol, I vaguely remember seeing the idea float around before, didn't realize it was from you in this very thread.
hb commented 2025年09月03日 02:03:49 +02:00 (Migrated from code.blicky.net)
Copy link

I only recently noticed that you've release ncdu 2.9` (https://dev.yorhel.nl/ncdu/changes2) that implements this. Nice - thank you.

For others, the man ncdu (https://dev.yorhel.nl/ncdu/man) explains how it works and has some nice examples;

--delete-command command

When set to a non-empty string, replace the built-in file deletion feature with a custom shell command.

The absolute path of the item to be deleted is appended to the given command and the result is evaluated in a shell. The command is run from the same directory that ncdu itself was started in. The NCDU_DELETE_PATH environment variable is set to the absolute path of the item to be deleted and NCDU_LEVEL is set in the same fashion as when spawning a shell from within ncdu.

After command completion, the in-memory view of the selected item is refreshed and directory sizes are adjusted as necessary. This is not a full refresh of the complete directory tree, so if the item has been renamed or moved to another directory, it's new location is not automatically picked up.

For example, to use rm(1) interactive mode to prompt before each deletion:

 ncdu --no-confirm-delete --delete-command 'rm -ri --'

Or to move files to trash:

 ncdu --delete-command 'gio trash --'

To add to the above documentation, another example is

 ncdu --delete-command 'trash-put --'

which uses trash-cli - a tool that is respects the freedesktop.org trashcan (i.e. ~/.local/share/Trash/ on most systems), which is what most Linux window managers uses as the 'Trash' folder. I can also confirm that you can prefix with custom environment variable, e.g.

 ncdu --delete-command "XDG_DATA_HOME='/alt/path/to/local/share' trash-put --"

PS. For others reading this later, the trailing -- is standard in POSIX and means "end of options", which tells the command that anything following should not be command-line options, but an operand (here a file or a directory). This allows you to delete files and folders starting with a hyphen, e.g. trash-put -- -a-real-file.txt works, whereas trash-put -a-real-file.txt would give an error "trash-put: error: unrecognized arguments: -a-real-file.txt".

I only recently noticed that you've release ncdu 2.9` (https://dev.yorhel.nl/ncdu/changes2) that implements this. Nice - thank you. For others, the `man ncdu` (https://dev.yorhel.nl/ncdu/man) explains how it works and has some nice examples; `--delete-command command` When set to a non-empty string, replace the built-in file deletion feature with a custom shell command. The absolute path of the item to be deleted is appended to the given command and the result is evaluated in a shell. The command is run from the same directory that `ncdu` itself was started in. The `NCDU_DELETE_PATH` environment variable is set to the absolute path of the item to be deleted and `NCDU_LEVEL` is set in the same fashion as when spawning a shell from within `ncdu`. After command completion, the in-memory view of the selected item is refreshed and directory sizes are adjusted as necessary. This is not a full refresh of the complete directory tree, so if the item has been renamed or moved to another directory, it's new location is not automatically picked up. For example, to use `rm(1)` interactive mode to prompt before each deletion: ```sh ncdu --no-confirm-delete --delete-command 'rm -ri --' ``` Or to move files to trash: ```sh ncdu --delete-command 'gio trash --' ``` --- To add to the above documentation, another example is ```sh ncdu --delete-command 'trash-put --' ``` which uses [trash-cli](https://github.com/andreafrancia/trash-cli) - a tool that is respects the freedesktop.org trashcan (i.e. `~/.local/share/Trash/` on most systems), which is what most Linux window managers uses as the 'Trash' folder. I can also confirm that you can prefix with custom environment variable, e.g. ```sh ncdu --delete-command "XDG_DATA_HOME='/alt/path/to/local/share' trash-put --" ``` PS. For others reading this later, the trailing `--` is standard in POSIX and means "end of options", which tells the command that anything following should _not_ be command-line options, but an operand (here a file or a directory). This allows you to delete files and folders starting with a hyphen, e.g. `trash-put -- -a-real-file.txt` works, whereas `trash-put -a-real-file.txt` would give an error "trash-put: error: unrecognized arguments: -a-real-file.txt".
Sign in to join this conversation.
No Branch/Tag specified
zig
zig0.16
master
zig-threaded
openat
chdir
clear
compll
v2.9.3
v2.9.2
v2.9.1
v2.9
v2.8.2
v2.8.1
v2.8
v1.22
v1.21
v2.7
v2.6
v2.5
v1.20
v2.4
v1.19
v2.3
v1.18.1
v2.2.2
v1.18
v2.2.1
v2.2
v1.17
v2.1.2
v2.1.1
v2.1
v2.0.1
v2.0
v2.0-beta3
v2.0-beta2
v2.0-beta1
v1.16
v1.15.1
v1.15
v1.14.2
v1.14.1
v1.14
v1.13
v1.12
v1.11
v1.10
v1.9
v1.8
v1.7
v1.6
v1.5
v1.4
v1.3
v1.2
v1.1
No labels
1.x
2.x
bug
feature
imported
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
selfisekai/ncsu#215
Reference in a new issue
selfisekai/ncsu
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?