tangled
alpha
login
or
join now
pdewey.com
/
yankbank-nvim
0
fork
atom
Neovim plugin improving access to clipboard history (mirror)
0
fork
atom
overview
issues
pulls
pipelines
refactor: added db clear option and changed db file path
ptdewey
2 years ago
59cd263f
9a5b7b26
+15
-20
4 changed files
expand all
collapse all
unified
split
.gitignore
lua
yankbank
init.lua
persistence
sql.lua
persistence.lua
+1
.gitignore
···
1
1
+
yankbank.db
+3
-9
lua/yankbank/init.lua
···
22
22
keymaps = {},
23
23
}
24
24
25
25
-
-- local plugin_path = debug.getinfo(1).source:sub(2):match("(.*/).*/.*/") or "./"
26
26
-
27
25
--- wrapper function for main plugin functionality
28
26
---@param opts table
29
27
--- TODO: read from persistent database if sql persist is set (allow multi-session sync)
30
28
local function show_yank_bank(opts)
31
31
-
-- Parse command arguments directly if args are provided as a string
32
32
-
opts = opts or default_opts
33
33
-
34
29
-- initialize buffer and populate bank
35
30
local bufnr, display_lines, line_yank_map =
36
31
menu.create_and_fill_buffer(yanks, reg_types, opts)
···
46
41
end
47
42
48
43
-- plugin setup
49
49
-
---@param opts table
44
44
+
---@param opts? table
50
45
function M.setup(opts)
51
46
-- merge opts with default options table
52
52
-
-- opts = vim.tbl_deep_extend("force", default_opts, opts or {})
53
53
-
opts = opts or default_opts
47
47
+
opts = vim.tbl_deep_extend("keep", opts or {}, default_opts)
54
48
55
49
-- enable persistence based on opts (needs to be called before autocmd setup)
56
50
yanks, reg_types = persistence.setup(opts)
···
58
52
-- create clipboard autocmds
59
53
clipboard.setup_yank_autocmd(yanks, reg_types, opts)
60
54
61
61
-
-- Create user command
55
55
+
-- create user command
62
56
vim.api.nvim_create_user_command("YankBank", function()
63
57
show_yank_bank(opts)
64
58
end, { desc = "Show Recent Yanks" })
+1
-7
lua/yankbank/persistence.lua
···
7
7
---@param reg_type string
8
8
---@param opts table
9
9
function M.add_entry(entry, reg_type, opts)
10
10
-
if not opts.persist_type then
11
11
-
return
12
12
-
elseif opts.persist_type == "sqlite" then
10
10
+
if opts.persist_type == "sqlite" then
13
11
persistence:insert_yank(entry, reg_type)
14
12
end
15
13
end
···
23
21
return {}, {}
24
22
elseif opts.persist_type == "sqlite" then
25
23
persistence = require("yankbank.persistence.sql").setup(opts)
26
26
-
vim.api.nvim_create_user_command("YankView", function()
27
27
-
print(vim.inspect(persistence:get()))
28
28
-
end, {})
29
29
-
30
24
return persistence:get_bank()
31
25
else
32
26
return {}, {}
+10
-4
lua/yankbank/persistence/sql.lua
···
2
2
3
3
local sqlite = require("sqlite.db")
4
4
5
5
-
local dbdir = vim.fn.stdpath("data") .. "/databases"
5
5
+
-- local dbdir = vim.fn.stdpath("data") .. "/databases"
6
6
+
local dbdir = debug.getinfo(1).source:sub(2):match("(.*/).*/.*/.*/") or "./"
6
7
local max_entries = 10
7
8
8
9
---@class YankBankDB:sqlite_db
···
89
90
function M.setup(opts)
90
91
max_entries = opts.max_entries
91
92
92
92
-
-- TODO: move database into plugin directory instead to allow easier uninstall
93
93
-
if vim.fn.isdirectory(dbdir) == 0 then
94
94
-
vim.fn.mkdir(dbdir, "p")
93
93
+
vim.api.nvim_create_user_command("YankBankClearDB", function()
94
94
+
data:remove()
95
95
+
end, {})
96
96
+
97
97
+
if opts.debug == true then
98
98
+
vim.api.nvim_create_user_command("YankBankViewDB", function()
99
99
+
print(vim.inspect(data:get()))
100
100
+
end, {})
95
101
end
96
102
97
103
return data