Repository navigation
[Plugins] Working with the system trash using the Lua API #4466
Describe the questionThere looks to be an Is this API available for user plugins? Is so, are there any examples of using Additionally, if you have the path to a file, how to you send it to the trash from Lua? I was trying something like If the API is not for plugins, then is the best way to manage the trash just Thanks! Checklist
|
Replies: 2 comments 3 replies
|
it's reachable from any plugin (
local ents, err = fs.trash.list() -- top level of the trash
for _, ent in ipairs(ents or {}) do
if ent.original and tostring(ent.original) == "/home/me/notes.txt" then
local ok, err = fs.trash.restore { ent }
end
end(these are async, so call them from an async plugin context, not a sync one) for sending a path to the trash there's no |
|
Is
What Restore a file by its original path: return {
entry = function(_, job)
local target = job.args[1] -- e.g. "/home/me/notes/todo.md"
local ents, err = fs.trash.list()
if not ents then
return ya.notify { title = "Trash", content = tostring(err), timeout = 5, level = "error" }
end
for _, ent in ipairs(ents) do
if ent.original and tostring(ent.original) == target then
local ok, err = fs.trash.restore { ent }
if not ok then
ya.notify { title = "Trash", content = "Restore failed: " .. tostring(err), timeout = 5, level = "error" }
end
return
end
end
end,
}If the destination already exists, Sending a path to the trash: there's no ya.emit("reveal", { Url(path) })
ya.emit("remove", { force = true, hovered = true }) -- no `permanently`, so it goes to the trashor, if you don't want to move the cursor, call an external tool with |
it's reachable from any plugin (
fs.trashis just a field onfs), but heads up it's only on main/nightly right now and isn't documented, so it could still change.entthere is aTrashEntryuserdata. you don't build it yourself, you get one fromfs.trash.list()orfs.trash.entry{ top = ..., rel = ... }. it haskey,top,rel,name,original(where it came from),stat, etc. restore takes a list of them:(these are async, so call them from an async plugin context, not a sy…