Skip to content

Commit 0310bb4

Browse files
committed
Update cpy_buffers plugin configuration to support yanking registers
1 parent 983e3c0 commit 0310bb4

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Cpy Buffers is a Neovim plugin that leverages Telescope to enable copying the co
66

77
https://github.com/adia-dev/cpy_buffers.nvim/assets/63371699/9c6a5090-4ffa-4b78-8296-a3391a17c840
88

9-
10-
119
## Requirements
1210

1311
- Neovim (0.8.0 or higher)
@@ -36,6 +34,10 @@ To initialize the plugin with (optional) custom configurations, add the followin
3634

3735
```lua
3836
require('cpy_buffers').setup({
37+
-- register to use for copy operations
38+
-- e.g: `+` will use the system clipboard (default)
39+
-- e.g: `"` will use the unnamed register, good for yanking inside vim
40+
register = "+",
3941
keymaps = {
4042
open_picker = "<leader>fc",
4143
toggle_hidden = "<leader>g",

lua/cpy_buffers/config.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
local M = {}
22

33
M.defaults = {
4+
-- register to use for copy operations
5+
-- e.g: `+` will use the system clipboard (default)
6+
-- e.g: `"` will use the unnamed register, good for yanking inside vim
7+
register = "+",
48
keymaps = {
59
open_picker = "<leader>fc",
610
toggle_selection = "<TAB>",

lua/cpy_buffers/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function M.setup(opts)
88
opts = opts or {}
99
config.setup(opts)
1010
keymaps.setup()
11-
commands.register_commands()
11+
commands.register_commands()
1212
end
1313

1414
return M

lua/cpy_buffers/utils.lua

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ local M = {}
77

88
M.selected_entries = {}
99

10-
11-
1210
function M.copy_contents_of_selected_files()
1311
local contents = {}
1412
local paths = {}
@@ -30,13 +28,12 @@ function M.copy_contents_of_selected_files()
3028

3129

3230
local all_contents = table.concat(contents, "\n\n")
33-
vim.fn.setreg("+", all_contents)
31+
vim.fn.setreg(config.get_config().register, all_contents)
3432

3533
if vim.tbl_isempty(contents) then
3634
vim.api.nvim_echo({ { "No files were copied", "WarningMsg" } }, true, {})
3735
return
3836
else
39-
-- message to print the paths of the copied files in a bullet list
4037
local message = "Copied the contents of the following files:\n"
4138
for _, path in ipairs(paths) do
4239
message = message .. " - " .. path .. "\n"
@@ -57,15 +54,12 @@ function M.copy_all_files(prompt_bufnr)
5754
return
5855
end
5956

60-
-- Select all entries
6157
for _, entry in ipairs(entries) do
6258
M.selected_entries[entry.value] = true
6359
end
6460

65-
-- Now copy the contents
6661
M.copy_contents_of_selected_files()
6762

68-
-- Close the picker
6963
actions.close(prompt_bufnr)
7064
M.selected_entries = {}
7165
end
@@ -228,8 +222,7 @@ function M.attach_mappings(prompt_bufnr, map)
228222
key = cfg.keymaps.toggle_hidden,
229223
action = function()
230224
config.toggle_hidden()
231-
-- refresh the picker
232-
local current_picker = action_state.get_current_picker(prompt_bufnr)
225+
233226
local rg_command
234227
if config.get_state().hide_hidden_files then
235228
rg_command = { "rg", "--files", "--hidden", "--glob", "!.git/*", "--glob", "!node_modules/*",
@@ -242,6 +235,7 @@ function M.attach_mappings(prompt_bufnr, map)
242235
table.insert(rg_command, opt)
243236
end
244237

238+
local current_picker = action_state.get_current_picker(prompt_bufnr)
245239
current_picker:refresh(finders.new_oneshot_job(rg_command))
246240

247241
if config.get_state().hide_hidden_files then

0 commit comments

Comments
 (0)