This commit is contained in:
2025-11-03 12:39:56 +01:00
parent 4f84e06f39
commit 7426087e69
2 changed files with 35 additions and 11 deletions

View File

@@ -1,5 +1,16 @@
# Easy encryption with gpg for files # Easy encryption with gpg for files
WARNING: This is not indented for public usage yet because it has some hardcoded things ## Usage
Code was taken from `yazi-rs`. Install with `ya pkg add Ascyii/gpg`.
Setup in `init.lua` with
```lua
require("gpg"):setup {
default = "username@example.com",
delete = true,
}
```
Code was taken from `yazi-rs` and `Rolv-Apneseth`.

View File

@@ -2,7 +2,7 @@
local function info(content) local function info(content)
return ya.notify { return ya.notify {
title = "Gpg", title = "Gpg information",
content = content, content = content,
timeout = 5, timeout = 5,
} }
@@ -13,23 +13,36 @@ local hovered_url = ya.sync(function()
return h and h.url return h and h.url
end) end)
local get_state_attr = ya.sync(function(state, attr)
return state[attr]
end)
return { return {
setup = function(state, options)
state.delete = options.path or true
state.default = options.default
end,
entry = function() entry = function()
local delete, default = get_state_attr("delete"), get_state_attr("default")
local hovered = hovered_url() local hovered = hovered_url()
if not hovered then if not hovered then
return info("No file selected") return info("No file selected")
end end
info(tostring(hovered)) if not default then
return info("No recipient set")
local output, err = Command("gpg"):arg("--yes"):arg("--recipient"):arg("jonashahn1@gmx.net"):arg("--output"):arg(tostring(hovered) .. ".gpg"):arg("--encrypt"):arg(tostring(hovered)):output()
if not output then
return info("Failed to gpg diff, error: " .. err)
end end
info("Done!") local _, err = Command("gpg"):arg("--yes"):arg("--recipient"):arg(default):arg("--output"):arg(tostring(hovered) .. ".gpg"):arg("--encrypt"):arg(tostring(hovered)):output()
if err then
return info("Failed to gpg with error: " .. err)
end
ya.clipboard(output.stdout) -- Delete the plain file
info("Diff copied to clipboard") if delete == true then
os.remove(hovered)
end
info("Done encrypting the file! The plain one is deleted now.")
end, end,
} }