diff options
| author | kongjun <kongjun18@outlook.com> | 2025-04-29 06:51:01 +0000 |
|---|---|---|
| committer | kongjun <kongjun18@outlook.com> | 2025-04-29 06:59:38 +0000 |
| commit | 872632670c31f682f3db01707468dbc12f154ab4 (patch) | |
| tree | f8e75de6fa3dddc291a0a3c239e2dc616d256a8f /lua/encrypt/init.lua | |
| parent | e6057b3c13f004477f4963f3cdf054e5ca1bf2f4 (diff) | |
| download | encrypt.nvim-872632670c31f682f3db01707468dbc12f154ab4.tar.gz | |
feat: :X decrypts or encrypts files
Diffstat (limited to 'lua/encrypt/init.lua')
| -rw-r--r-- | lua/encrypt/init.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lua/encrypt/init.lua b/lua/encrypt/init.lua index cfa1aa6..ea5368f 100644 --- a/lua/encrypt/init.lua +++ b/lua/encrypt/init.lua @@ -5,14 +5,18 @@ local helpers = require("encrypt.helpers") local function setup() vim.api.nvim_create_user_command("X", function() - setupBuffer(helpers.BUFTYPE.decrypted) - encrypt() + if helpers.bufferEncrypted() then + setupBuffer(helpers.BUFTYPE.encrypted) + decrypt() + else + setupBuffer(helpers.BUFTYPE.plaintext) + encrypt() + end end, {}) vim.api.nvim_create_autocmd({ "BufReadPost" }, { callback = function() - local first_line = vim.api.nvim_buf_get_lines(0, 0, 1, false)[1] - if first_line == helpers.ENCRYPTED_PREFIX then + if helpers.bufferEncrypted() then setupBuffer(helpers.BUFTYPE.encrypted) decrypt() end |
