-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for trashing files #165
Conversation
3e902d8
to
b6c1816
Compare
aff6745
to
165d57e
Compare
That is a lot of code 🤣 . I skimmed over it, but could not find obvious issues. Will test the branch in my config for a while. In regards to win32: AFAICT, RECYCLE_BIN is only accessible via APIs: https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shqueryrecyclebinw Is shelling out to PowerShell the most realistic approach? Other nvim plugins seem to rely on third-party cli tools: nvim-tree/nvim-tree.lua#279 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on linux with PopOS/Gnome and basic seem to work fine!
One potential issue: When trashing a file via Oil, but restoring via Gnome Rubbish Bin (nautilus), the file seems to get purged instead. At least I cannot find it anywhere. This does not happen when thrashing and restoring from Oil to Oil nor from Gnome to Gnome. Maybe some subtle difference in the trash info file?
lua/oil/view.lua
Outdated
|
||
-- Show original location of trash file as virtual text | ||
if adapter.name == "trash" and bufname == "oil-trash:///" then | ||
local ns = vim.api.nvim_create_namespace("OilVtext") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional, but perhaps not intuitive. You're using the Linux version which has support for listing the trash files per-directory. Since you're looking at the trashed files from a specific directory, there's no point to displaying the original path. If you open the root :Oil --trash /
it shows all trashed files, and the original path for each.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, virtual text shows up fine in root trash.
To be honest, it is pretty unintuitive (for me).
What I thought would happen is:
- virtual text is always visible
- listing of thrash files is per-directory recursively downwards
Now that I know how it works, it is definitely usable though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain more what you mean by "per-directory recursively downwards"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, given the following directory state (trashed files are marked with *):
- project
- fileA
- fileB
- fileC*
- dirA
- fileA.A
- fileA.B*
- fileA.C
- dirA.D
- fileA.D.A*
- fileA.D.B
- dirB
- fileB.A
- fileB.B*
- fileB.C*
Oil --trash project
shows
- fileC -> **virtual text...**
- fileA.B -> **...**
- fileA.D.A -> **...**
- fileB.B -> **...**
- fileB.c -> **...**
Oil --trash dirA
shows
- fileA.B -> **...**
- fileA.D.A -> **...**
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reworked the display logic. The trash directory will now show files that were trashed from that directory, and also directories that lead to trashed files from subdirs. When you are at the root of a trash scope (the root of a device, or the filesystem root), all trashed files will be visible.
I've also changed it so that trashed files will always have virtual text that displays their original path.
Thanks for testing! Very odd behavior with nautilus; it does sound like there must be some difference between the two trashinfo files. If you get a chance to check, I'd be curious to know if you spot anything. I'll also test it out next time I'm on my linux machine. |
85b5486
to
b62f680
Compare
I tested out the trash + restore functionality on both dolphin and nautilus, and they both seemed to work as expected when interacting with files trashed or restored by oil. If you have any pointers on getting a repro I would appreciate it |
I treid to reproduce it but could not! While I found a difference in trashinfo files created with # nushell rm --trash
# test.txt.trashinfo
[Trash Info]
Path=/home/oli/test.txt
DeletionDate=2023-10-06T16:54:27
# gnome nautilus delete
# test.txt.trashinfo
[Trash Info]
Path=/home/oli/test.txt
DeletionDate=2023-10-06T16:57:52
# Oil Trash delete
# test.txt-1696604368.814785.trashinfo
[Trash Info]
Path=/home/oli/test.txt
DeletionDate=2023-10-06T16:59:28 I guess those numbers are an encoding of the deletion date? Oil is probably more spec compliant then others :) |
Glad the issues didn't reproduce! The difference in trash file names is not important. Neither implementation is more or less spec compliant. From the spec in the "Contents of a trash directory" section:
So it's a nice-to-have for the name of the file to be the same or related to the original name, but officially it doesn't matter. |
b62f680
to
98294e5
Compare
This feature is awesome! It seems like I've run into a little snag with my setup though. It looks like the trash buffer doesn't necessarily share the same column settings as the regular buffer, and restoring files from trash with a different column format fails. Here's my setup: require("oil").setup({
columns = {
"icon",
"size",
},
delete_to_trash = true,
view_options = {
show_hidden = true,
},
}) Restoring files looks like this ( And this is the error message when attempting to write:
I don't know if I'm actually proposing the correct mechanism for the failure, but it did start working after I removed the size option. I hope this helps! |
@CorvusPrudens that does help! This was actually a pre-existing issue that could happen when moving files over ssh, but the trash feature added more ways for it to happen. Should be fixed by 4088efb, and I've rebased this PR. |
6f33ea8
to
781caf1
Compare
9487fdf
to
2e70af6
Compare
closes #99
Adds built-in support for trash. As with the previous implementation, set
delete_to_trash = true
to cause your deleted files to go to the trash. There are two ways to view the trash: there's thetoggle_trash
action (bound tog\
by default), or you can run:Oil --trash
. If you delete files from the trash they will be permanently deleted (purged). To restore files, just delete them from the trash buffer and paste them wherever you like, the same as how you normally move files. There are different experiences depending on your OS:Linux:
toggle_trash
shows you the files that were deleted from your current directory. To view the entire trash bin use:Oil --trash /
(or use-
to navigate to the root of the trash). You will notice that some edits in the trash directory will do nothing. For example, you cannot rename or copy a file in the trash; you also cannot create new files in the trash.Mac:
This implementation can only view the trash as one big bin. It's more similar to just viewing a normal oil directory, and should work the same.
Windows:
No support yet. I hate developing in Windows, so I'm dragging my feet. PRs welcome.
Anyone interested in trash functionality should try this out and leave feedback/bug reports. Once it seems solid enough for a while I'll merge.