···115| persist_type | string defining persistence type "sqlite" or nil | `nil` |
116| db_path | string defining database file path for use with sqlite persistence | plugin install directory |
117| bind_indices | optional string to be used for keybind prefix for pasting by index number (i.e. "<leader>p") | `nil` |
00118119120#### Example Configuration
···122```lua
123{
124 "ptdewey/yankbank-nvim",
000125 config = function()
126 require('yankbank').setup({
127 max_entries = 9,
···137 yank_register = "+",
138 },
139 bind_indices = "<leader>p"
000140 })
141 end,
142}
···187-- map to '<leader>y'
188vim.keymap.set("n", "<leader>y", "<cmd>YankBank<CR>", { noremap = true })
189```
0000190191---
192
···115| persist_type | string defining persistence type "sqlite" or nil | `nil` |
116| db_path | string defining database file path for use with sqlite persistence | plugin install directory |
117| bind_indices | optional string to be used for keybind prefix for pasting by index number (i.e. "<leader>p") | `nil` |
118+| pickers | table containing all pickers. | `{}` |
119+| pickers.snacks | boolean | `false` |
120121122#### Example Configuration
···124```lua
125{
126 "ptdewey/yankbank-nvim",
127+ dependencies = {
128+ "folke/snacks.nvim", -- (optional) - snacks picker integration
129+ },
130 config = function()
131 require('yankbank').setup({
132 max_entries = 9,
···142 yank_register = "+",
143 },
144 bind_indices = "<leader>p"
145+ pickers = {
146+ snacks = true,
147+ },
148 })
149 end,
150}
···195-- map to '<leader>y'
196vim.keymap.set("n", "<leader>y", "<cmd>YankBank<CR>", { noremap = true })
197```
198+199+### Snacks Picker
200+If `pickers.snacks` is set to true in the setup options, the snacks picker can be used to open the yankbank menu.
201+This can be triggered by running the command `:YankBankSnacks` or using `Snacks.picker.yankbank()` as you would any other snacks picker.
202203---
204
+5-1
lua/yankbank/init.lua
···13 -- enable persistence based on opts (needs to be called before autocmd setup)
14 local yanks, reg_types, pins = persistence.setup()
15 state.init(yanks, reg_types, pins, state.get_opts())
16-17 initialized = true
18end
19···60 persist_type = nil,
61 db_path = nil,
62 bind_indices = nil,
063 }
6465 -- merge opts with default options table
···93 desc = "Paste YankBank entry " .. i,
94 })
95 end
000096 end
97end
98
···13 -- enable persistence based on opts (needs to be called before autocmd setup)
14 local yanks, reg_types, pins = persistence.setup()
15 state.init(yanks, reg_types, pins, state.get_opts())
016 initialized = true
17end
18···59 persist_type = nil,
60 db_path = nil,
61 bind_indices = nil,
62+ pickers = {},
63 }
6465 -- merge opts with default options table
···93 desc = "Paste YankBank entry " .. i,
94 })
95 end
96+ end
97+98+ if merged_opts.pickers.snacks then
99+ require("yankbank.pickers.snacks").setup()
100 end
101end
102
···1+-- luacheck: globals Snacks
2+local M = {}
3+4+---@type snacks.picker.Config
5+local snacks_source = {
6+ title = "YankBank",
7+ finder = function()
8+ local yanks = require("yankbank.api").get_all()
9+ local items = {}
10+ for i = 1, #yanks do
11+ local yank = yanks[i]
12+ local yank_text = yank.yank_text
13+ table.insert(items, {
14+ label = tostring(i),
15+ reg = tostring(i),
16+ -- This is not used right now, but might be useful in the future
17+ -- to determine how to paste the content
18+ reg_type = yank.reg_type,
19+ -- data is used as the paste content
20+ data = yank_text,
21+ -- text is used by the matcher for searching
22+ text = yank_text,
23+ -- value is used to display in the picker
24+ value = yank_text,
25+ preview = {
26+ text = yank_text,
27+ -- Currently this is pinned to the current buffer's filetype
28+ -- as we don't store the filetype of each yank.
29+ -- This should be sufficient, as you would usually want to
30+ -- paste into the same filetype you yanked from.
31+ ft = vim.bo.filetype,
32+ },
33+ })
34+ end
35+ return items
36+ end,
37+ format = "register",
38+ preview = "preview",
39+ confirm = { "paste", "close" },
40+}
41+42+function M.setup()
43+ if Snacks and Snacks.picker then
44+ Snacks.picker.sources.yankbank = snacks_source
45+ end
46+ vim.api.nvim_create_user_command("YankBankSnacks", function()
47+ if Snacks then
48+ Snacks.picker(snacks_source)
49+ else
50+ vim.notify("Yank bank: Snacks is not loaded", vim.log.levels.ERROR)
51+ end
52+ end, {
53+ desc = "Open yankbank in snacks picker",
54+ })
55+end
56+57+return M