local M = {}
|
|
|
|
M.install = { src = "https://github.com/nvim-mini/mini.pick" }
|
|
|
|
M.setup = function()
|
|
local pick = require('mini.pick')
|
|
|
|
pick.setup({
|
|
mappings = {
|
|
paste_from_clipboard = {
|
|
char = '<C-r>',
|
|
func = function()
|
|
local clipboard = vim.fn.getreg('+')
|
|
local current_query = pick.get_picker_query() or {}
|
|
-- Query is an array of strings, join and append clipboard
|
|
local query_text = type(current_query) == 'table' and table.concat(current_query, '') or current_query
|
|
local new_query = query_text .. clipboard
|
|
-- Convert back to array of characters
|
|
local query_array = {}
|
|
for char in new_query:gmatch('.') do
|
|
table.insert(query_array, char)
|
|
end
|
|
pick.set_picker_query(query_array)
|
|
end,
|
|
},
|
|
send_to_qflist = {
|
|
char = '<C-q>',
|
|
func = function()
|
|
local items = pick.get_picker_items()
|
|
if not items or #items == 0 then
|
|
return
|
|
end
|
|
|
|
local qf_items = {}
|
|
for _, item in ipairs(items) do
|
|
if type(item) == 'string' then
|
|
-- Mini.pick uses null bytes (\0) as separators
|
|
local parts = vim.split(item, '\0', { plain = true })
|
|
|
|
if #parts >= 3 then
|
|
-- Format: path\0lnum\0col\0text
|
|
local path = parts[1]
|
|
local lnum = tonumber(parts[2]) or 1
|
|
local col = tonumber(parts[3]) or 1
|
|
local text = parts[4] or ''
|
|
|
|
table.insert(qf_items, {
|
|
filename = path,
|
|
lnum = lnum,
|
|
col = col,
|
|
text = text,
|
|
})
|
|
else
|
|
-- Just a file path
|
|
table.insert(qf_items, {
|
|
filename = item,
|
|
lnum = 1,
|
|
col = 1,
|
|
text = '',
|
|
})
|
|
end
|
|
end
|
|
end
|
|
|
|
if #qf_items > 0 then
|
|
vim.fn.setqflist(qf_items)
|
|
vim.cmd('copen')
|
|
end
|
|
pick.stop()
|
|
end,
|
|
},
|
|
},
|
|
window = {
|
|
config = function()
|
|
local height = math.floor(0.618 * vim.o.lines)
|
|
local width = math.floor(0.618 * vim.o.columns)
|
|
return {
|
|
anchor = 'NW',
|
|
height = height,
|
|
width = width,
|
|
row = math.floor(0.5 * (vim.o.lines - height)),
|
|
col = math.floor(0.5 * (vim.o.columns - width)),
|
|
}
|
|
end,
|
|
},
|
|
})
|
|
|
|
-- Keybind for git files
|
|
vim.keymap.set('n', '<leader>p', function()
|
|
pick.builtin.files({ tool = 'git' })
|
|
end, { desc = 'Pick Git Files' })
|
|
|
|
-- Keybind for git files
|
|
vim.keymap.set('n', '<leader>P', function()
|
|
pick.builtin.files()
|
|
end, { desc = 'Pick Files' })
|
|
|
|
vim.keymap.set('n', '<leader>f', function()
|
|
pick.builtin.grep_live()
|
|
end, { desc = 'Pick Search' })
|
|
|
|
vim.keymap.set('n', '<leader>H', function()
|
|
pick.builtin.help()
|
|
end, { desc = 'Pick Help' })
|
|
end
|
|
|
|
return M
|