Something went wrong. Try again.
Neovim plugin improving access to clipboard history (mirror)
Something went wrong. Try again.
2.7 kB · 98 lines
Lua
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899local M = {}
local initialized = false
function M.ensure_initialized() if initialized then return end
local state = require("yankbank.state") local persistence = require("yankbank.persistence")
-- enable persistence based on opts (needs to be called before autocmd setup) local yanks, reg_types, pins = persistence.setup() state.init(yanks, reg_types, pins) initialized = trueend
--- wrapper function for main plugin functionalityfunction M.show() M.ensure_initialized()
local state = require("yankbank.state") local menu = require("yankbank.menu")
-- set up menu keybinds from defaults and state.get_opts().keymaps menu.setup()
local persistence = require("yankbank.persistence") local yanks = persistence.get_yanks() or state.get_yanks() state.set_yanks(yanks)
-- initialize buffer and populate bank local buf_data = menu.create_and_fill_buffer() if not buf_data then return end
-- open popup window buf_data.win_id = menu.open_window(buf_data)
-- set popup keybinds menu.set_keymaps(buf_data)end
-- plugin setup---@param opts? tablefunction M.setup(opts) -- default plugin options local default_opts = { max_entries = 10, sep = "-----", focus_gain_poll = false, num_behavior = "prefix", registers = { yank_register = "+", }, keymaps = {}, persist_type = nil, db_path = nil, bind_indices = nil, pickers = {}, }
-- merge opts with default options table local merged_opts = vim.tbl_deep_extend("keep", opts or {}, default_opts)
-- store config in state module (lazy loaded when needed) local state = require("yankbank.state") state.set_opts(merged_opts)
-- focus-gain polling autocmd (TextYankPost is registered in plugin/yankbank.lua) require("yankbank.clipboard").setup_focus_autocmd()
-- Bind 1-n if `bind_indices` is set to a string if merged_opts.bind_indices then for i = 1, merged_opts.max_entries do vim.keymap.set("n", merged_opts.bind_indices .. i, function() M.ensure_initialized() require("yankbank.helpers").smart_paste( state.get_yanks()[i], state.get_reg_types()[i], true ) end, { noremap = true, silent = true, desc = "Paste YankBank entry " .. i, }) end end
if merged_opts.pickers.snacks then require("yankbank.pickers.snacks").setup() endend
return M