This commit is contained in:
2025-11-03 12:43:04 +01:00
parent a5f2d8a3dc
commit 25c6ac9def
2 changed files with 8 additions and 8 deletions

View File

@@ -8,8 +8,8 @@ Setup in `init.lua` with
```lua ```lua
require("gpg"):setup { require("gpg"):setup {
default = "username@example.com", default_recipient = "username@example.com",
delete = true, delete_after = true,
} }
``` ```

View File

@@ -19,27 +19,27 @@ end)
return { return {
setup = function(state, options) setup = function(state, options)
state.delete = options.delete or true state.delete_after = options.delete_after or true
state.default = options.default state.default_recipient = options.default_recipient
end, end,
entry = function() entry = function()
local delete, default = get_state_attr("delete"), get_state_attr("default") local delete_after, default_recipient = get_state_attr("delete_after"), get_state_attr("default_recipient")
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
if not default then if not default_recipient then
return info("No recipient set") return info("No recipient set")
end end
local _, err = Command("gpg"):arg("--yes"):arg("--recipient"):arg(default):arg("--output"):arg(tostring(hovered) .. ".gpg"):arg("--encrypt"):arg(tostring(hovered)):output() local _, err = Command("gpg"):arg("--yes"):arg("--recipient"):arg(default_recipient):arg("--output"):arg(tostring(hovered) .. ".gpg"):arg("--encrypt"):arg(tostring(hovered)):output()
if err then if err then
return info("Failed to gpg with error: " .. err) return info("Failed to gpg with error: " .. err)
end end
-- Delete the plain file -- Delete the plain file
if delete == true then if delete_after == true then
os.remove(hovered) os.remove(hovered)
end end