master
Bryan 2025-10-01 22:27:14 -06:00
parent e57c3dcd47
commit 215725e8ce
1 changed files with 64 additions and 81 deletions

145
main.lua
View File

@ -1,97 +1,80 @@
local selected_or_hovered = ya.sync(function() local selected_or_hovered = ya.sync(function()
local tab, urls = cx.active, {} local tab, urls = cx.active, {}
for _, u in pairs(tab.selected) do for _, u in pairs(tab.selected) do
urls[#urls + 1] = { name = u:name(), url = tostring(u) } urls[#urls + 1] = { name = u:name(), url = tostring(u) }
end end
if #urls == 0 and tab.current.hovered then if #urls == 0 and tab.current.hovered then
urls[1] = { name = tab.current.hovered.url:name(), url = tostring(tab.current.hovered.url) } urls[1] = { name = tab.current.hovered.url:name(), url = tostring(tab.current.hovered.url) }
end end
return urls return urls
end) end)
local confirm_remove = function(file) local confirm_remove = function(file)
local title = "Remove " .. file.name .. "? y/n/a/c " local title = "Remove " .. file.name .. "? y/n/a/c "
local w = #title local w = #title
local input = ya.input({ local input = ya.input({
title = title, title = title,
value = "y", value = "y",
position = { "top-center", w = w }, position = { "top-center", w = w },
}) })
if input == "y" then if input == "y" then
return "y" return "y"
elseif input == "a" then elseif input == "a" then
return "a" return "a"
elseif input == "n" then elseif input == "n" then
return "n" return "n"
else else
return "c" return "c"
end end
-- end
-- local cand = ya.which({
-- cands = {
-- { on = "y", desc = "Yes" },
-- { on = "n", desc = "No" },
-- { on = "a", desc = "All" },
-- },
-- silent = true,
-- })
-- if cand == 1 then
-- return "y"
-- elseif cand == 2 then
-- return "n"
-- elseif cand == 3 then
-- return "a"
-- else
-- return "c"
-- end
end end
local remove_file = function(file) local remove_file = function(file)
local notify_success = function(name) local notify_success = function(name)
ya.notify({ ya.notify({
title = "Rip File", title = "Rip File",
content = "Burried " .. name, content = "Burried " .. name,
timeout = 2, timeout = 2,
}) })
end end
local notify_error = function(name) local notify_error = function(name)
ya.notify({ ya.notify({
title = "Rip File", title = "Rip File",
content = "Error removing " .. name, content = "Error removing " .. name,
timeout = 2, timeout = 2,
}) })
end end
local status, err = Command("rip"):arg(file.url):status() local status, err = Command("rip"):arg(file.url):status()
if not status or status.code ~= 0 then if not status or status.code ~= 0 then
notify_error(file.name) notify_error(file.name)
else else
notify_success(file.name) notify_success(file.name)
end end
end end
--- @sync entry
return { return {
entry = function() entry = function()
ya.manager_emit("escape", { visual = true }) ya.manager_emit("escape", { visual = true })
local files = selected_or_hovered() local files = selected_or_hovered()
local confirm_all = false local confirm_all = false
for _, file in ipairs(files) do for _, file in ipairs(files) do
if not confirm_all then if not confirm_all then
local should_remove = confirm_remove(file) local should_remove = confirm_remove(file)
if should_remove == "n" then if should_remove == "n" then
goto continue goto continue
elseif should_remove ~= "y" and should_remove ~= "a" then elseif should_remove ~= "y" and should_remove ~= "a" then
return return
elseif should_remove == "a" then elseif should_remove == "a" then
confirm_all = true confirm_all = true
end end
end end
remove_file(file) remove_file(file)
::continue:: ::continue::
end end
end, end,
} }