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.
I would also really appreciate that feature!
Maybe https://github.com/andreafrancia/trash-cli could be utilised.
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.
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 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"
Closing this in favor of #165.
@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.
^ 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.
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)
... 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
Lol, I vaguely remember seeing the idea float around before, didn't realize it was from you in this very thread.
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".
No due date set.
No dependencies set.
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?