mirror of
https://github.com/Ascyii/gpg.yazi.git
synced 2026-03-02 00:02:43 +01:00
Add decrypt support
This commit is contained in:
23
main.lua
23
main.lua
@@ -29,18 +29,23 @@ return {
|
|||||||
return info("No file selected")
|
return info("No file selected")
|
||||||
end
|
end
|
||||||
|
|
||||||
if hovered:match("%.gpg$") then
|
|
||||||
return info("This file is already encrypted")
|
|
||||||
end
|
|
||||||
|
|
||||||
if not default_recipient 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_recipient):arg("--output"):arg(hovered ..
|
if hovered:match("%.gpg$") then
|
||||||
".gpg"):arg("--encrypt"):arg(hovered):output()
|
local plain_hovered = hovered:gsub("%.gpg$", "")
|
||||||
if err then
|
local _, err = Command("gpg"):arg("--yes"):arg("--recipient"):arg(default_recipient):arg("--output"):arg(plain_hovered):arg("--decrypt"):arg(hovered):output()
|
||||||
return info("Failed to gpg with error: " .. err)
|
if err then
|
||||||
|
return info("Failed to gpg with error: " .. err)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local _, err = Command("gpg"):arg("--yes"):arg("--recipient"):arg(default_recipient):arg("--output"):arg(hovered ..
|
||||||
|
".gpg"):arg("--encrypt"):arg(hovered):output()
|
||||||
|
if err then
|
||||||
|
return info("Failed to gpg with error: " .. err)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delete the plain file
|
-- Delete the plain file
|
||||||
@@ -48,6 +53,6 @@ return {
|
|||||||
os.remove(hovered)
|
os.remove(hovered)
|
||||||
end
|
end
|
||||||
|
|
||||||
info("Done encrypting the file! The plain one is deleted now.")
|
info("Done encrypting/decrypting the file! The plain one is deleted now.")
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user