diff --git a/README.md b/README.md index fc61fc4..4945d05 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ Cpy Buffers is a Neovim plugin that leverages Telescope to enable copying the co https://github.com/adia-dev/cpy_buffers.nvim/assets/63371699/9c6a5090-4ffa-4b78-8296-a3391a17c840 - - ## Requirements - Neovim (0.8.0 or higher) @@ -36,6 +34,10 @@ To initialize the plugin with (optional) custom configurations, add the followin ```lua require('cpy_buffers').setup({ + -- register to use for copy operations + -- e.g: `+` will use the system clipboard (default) + -- e.g: `"` will use the unnamed register, good for yanking inside vim + register = "+", keymaps = { open_picker = "fc", toggle_hidden = "g", diff --git a/lua/cpy_buffers/config.lua b/lua/cpy_buffers/config.lua index b397ce0..de4a51c 100644 --- a/lua/cpy_buffers/config.lua +++ b/lua/cpy_buffers/config.lua @@ -1,6 +1,10 @@ local M = {} M.defaults = { + -- register to use for copy operations + -- e.g: `+` will use the system clipboard (default) + -- e.g: `"` will use the unnamed register, good for yanking inside vim + register = "+", keymaps = { open_picker = "fc", toggle_selection = "", diff --git a/lua/cpy_buffers/init.lua b/lua/cpy_buffers/init.lua index d2c4ddd..3fddf2b 100644 --- a/lua/cpy_buffers/init.lua +++ b/lua/cpy_buffers/init.lua @@ -8,7 +8,7 @@ function M.setup(opts) opts = opts or {} config.setup(opts) keymaps.setup() - commands.register_commands() + commands.register_commands() end return M diff --git a/lua/cpy_buffers/utils.lua b/lua/cpy_buffers/utils.lua index d2266b4..484e626 100644 --- a/lua/cpy_buffers/utils.lua +++ b/lua/cpy_buffers/utils.lua @@ -7,8 +7,6 @@ local M = {} M.selected_entries = {} - - function M.copy_contents_of_selected_files() local contents = {} local paths = {} @@ -30,13 +28,12 @@ function M.copy_contents_of_selected_files() local all_contents = table.concat(contents, "\n\n") - vim.fn.setreg("+", all_contents) + vim.fn.setreg(config.get_config().register, all_contents) if vim.tbl_isempty(contents) then vim.api.nvim_echo({ { "No files were copied", "WarningMsg" } }, true, {}) return else - -- message to print the paths of the copied files in a bullet list local message = "Copied the contents of the following files:\n" for _, path in ipairs(paths) do message = message .. " - " .. path .. "\n" @@ -57,15 +54,12 @@ function M.copy_all_files(prompt_bufnr) return end - -- Select all entries for _, entry in ipairs(entries) do M.selected_entries[entry.value] = true end - -- Now copy the contents M.copy_contents_of_selected_files() - -- Close the picker actions.close(prompt_bufnr) M.selected_entries = {} end @@ -228,8 +222,7 @@ function M.attach_mappings(prompt_bufnr, map) key = cfg.keymaps.toggle_hidden, action = function() config.toggle_hidden() - -- refresh the picker - local current_picker = action_state.get_current_picker(prompt_bufnr) + local rg_command if config.get_state().hide_hidden_files then rg_command = { "rg", "--files", "--hidden", "--glob", "!.git/*", "--glob", "!node_modules/*", @@ -242,6 +235,7 @@ function M.attach_mappings(prompt_bufnr, map) table.insert(rg_command, opt) end + local current_picker = action_state.get_current_picker(prompt_bufnr) current_picker:refresh(finders.new_oneshot_job(rg_command)) if config.get_state().hide_hidden_files then