master
Bryan 2025-10-02 20:18:14 -06:00
parent 215725e8ce
commit d23a05e1a3
1 changed files with 77 additions and 66 deletions

143
main.lua
View File

@ -1,80 +1,91 @@
local notify = function(text)
ya.notify({
title = "Rip",
content = text,
timeout = 2,
})
end
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 if #tab.selected > 0 then
urls[#urls + 1] = { name = u:name(), url = tostring(u) } for _, u in pairs(tab.selected) do
end urls[#urls + 1] = tostring(u)
if #urls == 0 and tab.current.hovered then end
urls[1] = { name = tab.current.hovered.url:name(), url = tostring(tab.current.hovered.url) } end
end if #urls == 0 and tab.current.hovered then
return urls urls[1] = tostring(tab.current.hovered.url)
end
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 .. "? y/n/a/c "
local w = #title local w = #title
local input = ya.input({ local input, event = ya.input({
title = title, title = title,
value = "y", value = "y",
position = { "top-center", w = w }, position = { "center", w = w },
}) })
if input == "y" then if event ~= 1 then
return "y" return "c"
elseif input == "a" then end
return "a"
elseif input == "n" then if input == "y" then
return "n" return "y"
else elseif input == "a" then
return "c" return "a"
end elseif input == "n" then
return "n"
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):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)
notify_error(file.name) else
else notify_success(file)
notify_success(file.name) end
end
end end
--- @sync entry --- @sync entry
return { return {
entry = function() entry = function()
ya.manager_emit("escape", { visual = true }) ya.mgr_emit("escape", { visual = true })
local files = selected_or_hovered()
local confirm_all = false
for _, file in ipairs(files) do
if not confirm_all then
local should_remove = confirm_remove(file)
if should_remove == "n" then
goto continue
elseif should_remove ~= "y" and should_remove ~= "a" then
return
elseif should_remove == "a" then
confirm_all = true
end
end
local files = selected_or_hovered() remove_file(file)
local confirm_all = false ::continue::
end
for _, file in ipairs(files) do end,
if not confirm_all then
local should_remove = confirm_remove(file)
if should_remove == "n" then
goto continue
elseif should_remove ~= "y" and should_remove ~= "a" then
return
elseif should_remove == "a" then
confirm_all = true
end
end
remove_file(file)
::continue::
end
end,
} }