feat(picker.files): added ft option to filter by extension(s)

This commit is contained in:
Folke Lemaitre 2025-02-10 10:27:32 +01:00
parent d56cd48e4c
commit 12a7ea28b9
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
5 changed files with 25 additions and 2 deletions

View file

@ -193,6 +193,7 @@ M.diagnostics_buffer = {
---@field follow? boolean follow symlinks
---@field exclude? string[] exclude patterns
---@field args? string[] additional arguments
---@field ft? string|string[] file extension(s)
---@field rtp? boolean search in runtimepath
M.files = {
finder = "files",

View file

@ -72,6 +72,23 @@ local function get_cmd(opts, filter)
end
end
-- extensions
local ft = opts.ft or {}
ft = type(ft) == "string" and { ft } or ft
---@cast ft string[]
for _, e in ipairs(ft) do
if is_fd then
table.insert(args, "-e")
table.insert(args, e)
elseif is_rg then
table.insert(args, "-g")
table.insert(args, "*." .. e)
elseif is_find then
table.insert(args, "-name")
table.insert(args, "*." .. e)
end
end
-- hidden
if opts.hidden and is_fd_rg then
table.insert(args, "--hidden")