···3535}
3636```
37373838+The setup function also supports taking in a table of options:
3939+| Option | Type | Default |
4040+|-------------|--------------------------------------------|----------------|
4141+| max_entries | integer number of entries to show in popup | 10 |
4242+| sep | string separator to show between table entries | "-----" |
4343+4444+4545+If no separator is desired, pass in an empty string for sep:
4646+```lua
4747+ config = function()
4848+ require('yankbank').setup({
4949+ max_entries = 12,
5050+ sep = "",
5151+ })
5252+ end,
5353+```
5454+3855## Usage
39564057The popup menu can be opened with the command:`:YankBank`, an entry is pasted at the current cursor position by hitting enter, and the menu can be closed by hitting escape, ctrl-c, or q.
+5-4
lua/yankbank/data.lua
···22local M = {}
3344-- reformat yanks table for popup
55-function M.get_display_lines(yanks)
55+function M.get_display_lines(yanks, sep)
66 local display_lines = {}
77 local line_yank_map = {}
88 local yank_num = 0
···3939 table.insert(line_yank_map, i)
4040 end
41414242- -- Add a visual separator between yanks, aligned with the yank content
4343- -- TODO: allow turning off/on in plugin setup
4442 if i < #yanks then
4545- table.insert(display_lines, string.rep(" ", max_digits + 2) .. "------")
4343+ -- Add a visual separator between yanks, aligned with the yank content
4444+ if sep ~= "" then
4545+ table.insert(display_lines, string.rep(" ", max_digits + 2) .. sep)
4646+ end
4647 table.insert(line_yank_map, false)
4748 end
4849 end
+25-12
lua/yankbank/init.lua
···88-- initialize yanks tables
99local yanks = {}
1010local max_entries = 10
1111+local sep = "-----"
11121213-- wrapper function for main plugin functionality
1313-local function show_yank_bank()
1414- -- TODO: update max entries with passed in options
1515- local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, max_entries)
1414+local function show_yank_bank(args)
1515+ -- Parse command arguments directly if args are provided as a string
1616+ local opts = {}
1717+ if type(args) == "string" and args ~= "" then
1818+ local parts = vim.split(args, "%s+", {true})
1919+ opts.max_entries = tonumber(parts[1])
2020+ opts.sep = parts[2]
2121+ elseif type(args) == "table" then
2222+ -- If opts is already a table, use it directly (for programmatic calls)
2323+ opts = args
2424+ end
2525+2626+ -- Fallback to defaults if necessary
2727+ local max_entries_opt = opts.max_entries or max_entries
2828+ local sep_opt = opts.sep or sep
2929+3030+ local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt)
1631 local win_id = menu.open_window(bufnr, display_lines)
1732 menu.set_keymaps(win_id, bufnr, yanks, line_yank_map)
1833end
19342035-- plugin setup
2136function M.setup(opts)
2222- local o = {}
3737+ opts = opts or {}
23382439 -- parse opts
2525- if opts ~= nil then
2626- o.max_entries = opts.max_entries or max_entries
2727- else
2828- o.max_entries = max_entries
2929- end
4040+ max_entries = opts.max_entries or max_entries
4141+ sep = opts.sep or sep
30423143 -- create clipboard autocmds
3232- clipboard.setup_yank_autocmd(yanks, o.max_entries)
4444+ clipboard.setup_yank_autocmd(yanks, max_entries)
33453446 -- Create user command
3547 -- TODO: allow params (i.e. keymaps/max_entries/separator)
3636- vim.api.nvim_create_user_command("YankBank", show_yank_bank,
3737- { desc = "Show Recent Yanks" })
4848+ vim.api.nvim_create_user_command("YankBank", function(args)
4949+ show_yank_bank(args.args)
5050+ end, { desc = "Show Recent Yanks", nargs = "*" })
3851end
39524053return M
+6-6
lua/yankbank/menu.lua
···77local helpers = require("yankbank.helpers")
8899-- create new buffer and reformat yank table for ui
1010-function M.create_and_fill_buffer(yanks, max_entries)
1010+function M.create_and_fill_buffer(yanks, max_entries, sep)
1111 -- check the content of the system clipboard register
1212 -- TODO: this could be replaced with some sort of polling of the + register
1313 local text = vim.fn.getreg('+')
···2929 local current_filetype = vim.bo.filetype
3030 vim.api.nvim_buf_set_option(bufnr, 'filetype', current_filetype)
31313232- local display_lines, line_yank_map = data.get_display_lines(yanks)
3232+ local display_lines, line_yank_map = data.get_display_lines(yanks, sep)
33333434 -- replace current buffer contents with updated table
3535 vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, display_lines)
···4646 end
47474848 -- define buffer window width and height based on number of columns
4949- local width = math.min(max_width + 4, vim.api.nvim_get_option("columns") - 50)
5050- local height = math.min(#display_lines, vim.api.nvim_get_option("lines") - 4)
4949+ local width = math.min(max_width + 4, vim.api.nvim_get_option("columns"))
5050+ local height = math.min(#display_lines, vim.api.nvim_get_option("lines"))
51515252 -- open window
5353 local win_id = vim.api.nvim_open_win(bufnr, true, {
5454 relative = "editor",
5555 width = width,
5656 height = height,
5757- col = math.floor((vim.api.nvim_get_option("columns") - width) / 2 - 1),
5858- row = math.floor((vim.api.nvim_get_option("lines") - height) / 2 - 1),
5757+ col = math.floor((vim.api.nvim_get_option("columns") - width) / 2),
5858+ row = math.floor((vim.api.nvim_get_option("lines") - height) / 2),
5959 border = "rounded",
6060 style = "minimal",
6161 })