feat: search_file option for builtin fd command (#2029)
This commit is contained in:
@@ -899,6 +899,7 @@ builtin.find_files({opts}) *telescope.builtin.find_files()*
|
|||||||
(default: false)
|
(default: false)
|
||||||
{search_dirs} (table) directory/directories/files to
|
{search_dirs} (table) directory/directories/files to
|
||||||
search
|
search
|
||||||
|
{search_file} (string) specify a filename to search for
|
||||||
|
|
||||||
|
|
||||||
builtin.fd() *telescope.builtin.fd()*
|
builtin.fd() *telescope.builtin.fd()*
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ files.find_files = function(opts)
|
|||||||
local no_ignore_parent = opts.no_ignore_parent
|
local no_ignore_parent = opts.no_ignore_parent
|
||||||
local follow = opts.follow
|
local follow = opts.follow
|
||||||
local search_dirs = opts.search_dirs
|
local search_dirs = opts.search_dirs
|
||||||
|
local search_file = opts.search_file
|
||||||
|
|
||||||
if search_dirs then
|
if search_dirs then
|
||||||
for k, v in pairs(search_dirs) do
|
for k, v in pairs(search_dirs) do
|
||||||
@@ -221,8 +222,16 @@ files.find_files = function(opts)
|
|||||||
if follow then
|
if follow then
|
||||||
table.insert(find_command, "-L")
|
table.insert(find_command, "-L")
|
||||||
end
|
end
|
||||||
|
if search_file then
|
||||||
|
if command == "rg" then
|
||||||
|
table.insert(find_command, "-g")
|
||||||
|
table.insert(find_command, "*" .. search_file .. "*")
|
||||||
|
else
|
||||||
|
table.insert(find_command, search_file)
|
||||||
|
end
|
||||||
|
end
|
||||||
if search_dirs then
|
if search_dirs then
|
||||||
if command ~= "rg" then
|
if command ~= "rg" and not search_file then
|
||||||
table.insert(find_command, ".")
|
table.insert(find_command, ".")
|
||||||
end
|
end
|
||||||
for _, v in pairs(search_dirs) do
|
for _, v in pairs(search_dirs) do
|
||||||
@@ -243,6 +252,10 @@ files.find_files = function(opts)
|
|||||||
if follow then
|
if follow then
|
||||||
table.insert(find_command, 2, "-L")
|
table.insert(find_command, 2, "-L")
|
||||||
end
|
end
|
||||||
|
if search_file then
|
||||||
|
table.insert(find_command, "-name")
|
||||||
|
table.insert(find_command, "*" .. search_file .. "*")
|
||||||
|
end
|
||||||
if search_dirs then
|
if search_dirs then
|
||||||
table.remove(find_command, 2)
|
table.remove(find_command, 2)
|
||||||
for _, v in pairs(search_dirs) do
|
for _, v in pairs(search_dirs) do
|
||||||
@@ -265,6 +278,9 @@ files.find_files = function(opts)
|
|||||||
if search_dirs ~= nil then
|
if search_dirs ~= nil then
|
||||||
log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`."
|
log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`."
|
||||||
end
|
end
|
||||||
|
if search_file ~= nil then
|
||||||
|
log.warn "The `search_file` key is not available for the Windows `where` command in `find_files`."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.cwd then
|
if opts.cwd then
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_s
|
|||||||
---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false)
|
---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false)
|
||||||
---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false)
|
---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false)
|
||||||
---@field search_dirs table: directory/directories/files to search
|
---@field search_dirs table: directory/directories/files to search
|
||||||
|
---@field search_file string: specify a filename to search for
|
||||||
builtin.find_files = require_on_exported_call("telescope.builtin.files").find_files
|
builtin.find_files = require_on_exported_call("telescope.builtin.files").find_files
|
||||||
|
|
||||||
--- This is an alias for the `find_files` picker
|
--- This is an alias for the `find_files` picker
|
||||||
|
|||||||
Reference in New Issue
Block a user