This commit is contained in:
2025-11-03 11:57:22 +01:00
parent 9991032486
commit 7f9e731279
2 changed files with 37 additions and 49 deletions

View File

@@ -0,0 +1,3 @@
# Easy encryption with gpg for files
WARNING: This is not indented for public usage yet because it has some hardcoded things

View File

@@ -1,61 +1,46 @@
--- @since 25.5.31 --- @since 25.5.31
local selected_or_hovered = ya.sync(function() local selected_or_hovered = ya.sync(function()
local tab, paths = cx.active, {} local tab, paths = cx.active, {}
for _, u in pairs(tab.selected) do for _, u in pairs(tab.selected) do
paths[#paths + 1] = tostring(u) paths[#paths + 1] = tostring(u)
end end
if #paths == 0 and tab.current.hovered then if #paths == 0 and tab.current.hovered then
paths[1] = tostring(tab.current.hovered.url) paths[1] = tostring(tab.current.hovered.url)
end end
return paths return paths
end) end)
return { return {
entry = function() entry = function()
ya.emit("escape", { visual = true }) ya.emit("escape", { visual = true })
local urls = selected_or_hovered()
if #urls == 0 then
return ya.notify { title = "GPG Encrypt", content = "No file selected", level = "warn", timeout = 5 }
end
-- Ask for GPG recipient local urls = selected_or_hovered()
local recipient, event = ya.input { if #urls == 0 then
title = "GPG Recipient:", return ya.notify { title = "GPG Encrypt", content = "No file selected", level = "warn", timeout = 5 }
pos = { "top-center", y = 3, w = 50 }, end
}
if event ~= 1 or recipient == "" then
return
end
for _, file_path in ipairs(urls) do
local gpg_file = file_path .. ".gpg"
local status, err = Command("gpg")
:arg("--yes")
:arg("--batch")
:arg("--recipient")
:arg(recipient)
:arg("--output")
:arg(gpg_file)
:arg("--encrypt")
:arg(file_path)
:spawn()
:wait()
if not status or not status.success then for _, file_path in ipairs(urls) do
ya.notify { local gpg_file = file_path .. ".gpg"
title = "GPG Encrypt", ya.notify{title = "NOTI", content = file_path, level = "info"}
content = string.format("Encryption failed for %s: %s", file_path, status and status.code or err), local status, err = Command("gpg"):arg("--yes"):arg("--batch"):arg("--recipient"):arg("jonashahn1@gmx.net")
level = "error", :arg(gpg_file):arg("--encrypt"):arg(file_path):spawn():wait()
timeout = 5,
}
else
os.remove(file_path)
end
end
ya.refresh() if not status or not status.success then
ya.notify { title = "GPG Encrypt", content = "Encryption complete", level = "info", timeout = 3 } ya.notify {
end, title = "GPG Encrypt",
content = string.format("Encryption failed for %s: %s", file_path, status and status.code or err),
level = "error",
timeout = 5,
}
else
os.remove(file_path)
end
end
ya.refresh()
ya.notify { title = "GPG Encrypt", content = "Encryption complete", level = "info", timeout = 3 }
end,
} }