feat(picker): added exclude option for files and grep. Closes #581

This commit is contained in:
Folke Lemaitre 2025-01-17 14:35:28 +01:00
parent 5ab2621d81
commit 192fb31c4b
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 20 additions and 0 deletions

View file

@ -116,6 +116,7 @@ M.diagnostics_buffer = {
---@field ignored? boolean show ignored files
---@field dirs? string[] directories to search
---@field follow? boolean follow symlinks
---@field exclude? string[] exclude patterns
M.files = {
finder = "files",
format = "file",
@ -198,6 +199,7 @@ M.git_diff = {
---@field regex? boolean use regex search pattern (defaults to `true`)
---@field buffers? boolean search in open buffers
---@field need_search? boolean require a search pattern
---@field exclude? string[] exclude patterns
M.grep = {
finder = "grep",
format = "file",

View file

@ -30,6 +30,19 @@ local function get_cmd(opts, filter)
args = vim.deepcopy(args)
local is_fd, is_fd_rg, is_find, is_rg = cmd == "fd" or cmd == "fdfind", cmd ~= "find", cmd == "find", cmd == "rg"
-- exclude
for _, e in ipairs(opts.exclude or {}) do
if is_fd then
vim.list_extend(args, { "-E", e })
elseif is_rg then
vim.list_extend(args, { "-g", "!" .. e })
elseif is_find then
table.insert(args, "-not")
table.insert(args, "-path")
table.insert(args, e)
end
end
-- hidden
if opts.hidden and is_fd_rg then
table.insert(args, "--hidden")

View file

@ -26,6 +26,11 @@ local function get_cmd(opts, filter)
args = vim.deepcopy(args)
-- exclude
for _, e in ipairs(opts.exclude or {}) do
vim.list_extend(args, { "-g", "!" .. e })
end
-- hidden
if opts.hidden then
table.insert(args, "--hidden")