Skip to content

Commit

Permalink
Update cpy_buffers plugin configuration to support yanking registers
Browse files Browse the repository at this point in the history
  • Loading branch information
adia-dev committed Mar 16, 2024
1 parent 983e3c0 commit 0310bb4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = "<leader>fc",
toggle_hidden = "<leader>g",
Expand Down
4 changes: 4 additions & 0 deletions lua/cpy_buffers/config.lua
Original file line number Diff line number Diff line change
@@ -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 = "<leader>fc",
toggle_selection = "<TAB>",
Expand Down
2 changes: 1 addition & 1 deletion lua/cpy_buffers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 3 additions & 9 deletions lua/cpy_buffers/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ local M = {}

M.selected_entries = {}



function M.copy_contents_of_selected_files()
local contents = {}
local paths = {}
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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/*",
Expand All @@ -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
Expand Down

0 comments on commit 0310bb4

Please sign in to comment.