From bf1a25dbfe9a4368b10354cb46e4b3a0ab0a41a4 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+tobealive@users.noreply.github.com> Date: Fri, 1 Jul 2022 22:10:31 +0200 Subject: [PATCH] feat: search_file option for builtin fd command (#2029) --- doc/telescope.txt | 1 + lua/telescope/builtin/files.lua | 18 +++++++++++++++++- lua/telescope/builtin/init.lua | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index a736d18..6381b12 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -899,6 +899,7 @@ builtin.find_files({opts}) *telescope.builtin.find_files()* (default: false) {search_dirs} (table) directory/directories/files to search + {search_file} (string) specify a filename to search for builtin.fd() *telescope.builtin.fd()* diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index d6fa9b4..dddd18a 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -201,6 +201,7 @@ files.find_files = function(opts) local no_ignore_parent = opts.no_ignore_parent local follow = opts.follow local search_dirs = opts.search_dirs + local search_file = opts.search_file if search_dirs then for k, v in pairs(search_dirs) do @@ -221,8 +222,16 @@ files.find_files = function(opts) if follow then table.insert(find_command, "-L") 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 command ~= "rg" then + if command ~= "rg" and not search_file then table.insert(find_command, ".") end for _, v in pairs(search_dirs) do @@ -243,6 +252,10 @@ files.find_files = function(opts) if follow then table.insert(find_command, 2, "-L") end + if search_file then + table.insert(find_command, "-name") + table.insert(find_command, "*" .. search_file .. "*") + end if search_dirs then table.remove(find_command, 2) for _, v in pairs(search_dirs) do @@ -265,6 +278,9 @@ files.find_files = function(opts) if search_dirs ~= nil then log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`." 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 if opts.cwd then diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 145338b..71cb583 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -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_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_file string: specify a filename to search for builtin.find_files = require_on_exported_call("telescope.builtin.files").find_files --- This is an alias for the `find_files` picker