Neovim plugin improving access to clipboard history (mirror)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: fixed failing CI

ptdewey e0f1451a 369492b2

+24 -16
+2 -2
lua/yankbank/init.lua
··· 10 10 local yanks = {} 11 11 local reg_types = {} 12 12 13 - YANKS = {} 14 - REG_TYPES = {} 13 + -- YANKS = {} 14 + -- REG_TYPES = {} 15 15 16 16 local plugin_path = debug.getinfo(1).source:sub(2):match("(.*/).*/.*/") or "./" 17 17
+4 -3
lua/yankbank/menu.lua
··· 2 2 local M = {} 3 3 4 4 -- import clipboard functions 5 - local clipboard = require("yankbank.clipboard") 5 + -- local clipboard = require("yankbank.clipboard") 6 6 local data = require("yankbank.data") 7 7 local helpers = require("yankbank.helpers") 8 8 ··· 22 22 -- clipboard.add_yank(yanks, reg_types, text, reg_type, opts) 23 23 24 24 -- stop if yank table is empty 25 - if #yanks == 0 then 25 + if #yanks == 0 and #reg_types then 26 26 print("No yanks to show.") 27 27 return nil, nil, nil 28 28 end ··· 118 118 local k = vim.tbl_deep_extend("force", default_keymaps, opts.keymaps or {}) 119 119 120 120 -- merge default and options keymap tables 121 - opts.registers = vim.tbl_deep_extend("force", default_registers, opts.registers or {}) 121 + opts.registers = 122 + vim.tbl_deep_extend("force", default_registers, opts.registers or {}) 122 123 123 124 -- check table for number behavior option (prefix or jump, default to prefix) 124 125 opts.num_behavior = opts.num_behavior or "prefix"
+4 -3
lua/yankbank/persistence.lua
··· 2 2 local M = {} 3 3 4 4 local persistence = {} 5 + local db = nil 5 6 6 7 ---add entry from bank to 7 8 ---@param entry string|table ··· 13 14 elseif opts.persist_type == "file" then 14 15 persistence.add_to_bankfile(opts.persist_path, entry, reg_type) 15 16 elseif opts.persist_type == "sqlite" then 16 - -- TODO: implement sqlite persist 17 + persistence.add_to_yanktable(db, entry, reg_type) 17 18 end 18 19 end 19 20 ··· 35 36 reg_types 36 37 ) 37 38 elseif opts.persist_type == "sqlite" then 38 - -- TODO: 39 39 persistence = require("yankbank.persistence.sql") 40 - persistence.init_db(yanks, reg_types, opts.persist_path) 40 + db = persistence.init_db(yanks, reg_types, opts.persist_path) 41 + return yanks, reg_types 41 42 end 42 43 43 44 return {}, {}
+14 -8
lua/yankbank/persistence/sql.lua
··· 2 2 3 3 local sqlite = require("sqlite.db") 4 4 5 - -- @TODO: yank primary key? 5 + -- TODO: yank primary key? 6 6 -- integer tracking for table position not controlled by sqlite3 7 7 8 - -- create db table for yanks, PK is row id and will increment automatically 8 + ---create db table for yanks, PK is row id and will increment automatically 9 9 -- @param existing_yanks table 10 + -- @param reg_types table 10 11 -- @param uri string 11 12 -- @return sqlite_db 12 - function M.init_db(existing_yanks, uri) 13 + function M.init_db(existing_yanks, reg_types, uri) 13 14 local db = sqlite({ 14 15 uri = uri, 15 16 }) ··· 23 24 }) 24 25 local status = db:status() 25 26 27 + db:insert("yanks", { yank_content = existing_yanks, reg_type = reg_types }) 28 + 26 29 if status ~= nil then 27 30 print("yankbank db error: ", status.code) 28 31 end 29 - -- @TODO: add functionality to add existing yanks to the db table "yanks" 32 + -- TODO: add functionality to add existing yanks to the db table "yanks" 30 33 db:close() 31 34 return db 32 35 end ··· 68 71 69 72 function M.remove_by_yank_index(db, index) 70 73 db:open() 71 - local ret = db:select("yanks", { order_by = { asc = "id" }}) 74 + local ret = db:select("yanks", { order_by = { asc = "id" } }) 72 75 local id_to_remove = ret[index].id 73 76 local del = db:delete("yanks", { where = { id = id_to_remove } }) 77 + if del ~= nil then 78 + return del 79 + end 74 80 local status = db:status() 75 81 db:close() 76 82 return status == nil 77 83 end 78 84 79 85 -- test function for db operations 80 - local function test_db() 81 - local test_db = M.init_db({}, "/tmp/test_yankbank.db") 86 + local function test_database() 87 + local test_db = M.init_db({}, {}, "/tmp/test_yankbank.db") 82 88 -- print(vim.inspect(test_db)) 83 89 M.add_to_yanktable(test_db, "Sample Yank", "reg") 84 90 print(vim.inspect(M.get_yanks(test_db))) ··· 91 97 print(vim.inspect(M.get_yanks(test_db))) 92 98 end 93 99 94 - -- test_db() 100 + test_database() 95 101 96 102 return M