feat: find_command can be a function (#2000)

This commit is contained in:
Simon Hauser
2022-06-12 15:37:24 +02:00
committed by Simon Hauser
parent 77e2b8ceea
commit f6efef4c41
3 changed files with 22 additions and 19 deletions

View File

@@ -878,22 +878,24 @@ builtin.find_files({opts}) *telescope.builtin.find_files()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Options: ~ Options: ~
{cwd} (string) root dir to search from (default: cwd, {cwd} (string) root dir to search from (default:
use utils.buffer_dir() to search cwd, use utils.buffer_dir() to
relative to open buffer) search relative to open buffer)
{find_command} (table) command line arguments for `find_files` {find_command} (function|table) cmd to use for the search. Can be
to use for the search, overrides a fn(opts) -> tbl (default:
default: config autodetect)
{follow} (boolean) if true, follows symlinks (i.e. uses {follow} (boolean) if true, follows symlinks (i.e.
`-L` flag for the `find` command) uses `-L` flag for the `find`
{hidden} (boolean) determines whether to show hidden files command)
or not (default: false) {hidden} (boolean) determines whether to show hidden
{no_ignore} (boolean) show files ignored by .gitignore, files or not (default: false)
.ignore, etc. (default: false) {no_ignore} (boolean) show files ignored by .gitignore,
{no_ignore_parent} (boolean) show files ignored by .gitignore, .ignore, etc. (default: false)
.ignore, etc. in parent dirs. (default: {no_ignore_parent} (boolean) show files ignored by .gitignore,
false) .ignore, etc. in parent dirs.
{search_dirs} (table) directory/directories to search in (default: false)
{search_dirs} (table) directory/directories to search
in
builtin.fd() *telescope.builtin.fd()* builtin.fd() *telescope.builtin.fd()*

View File

@@ -153,11 +153,12 @@ files.grep_string = function(opts)
}):find() }):find()
end end
-- TODO: Maybe just change this to `find`.
-- TODO: Support `find` and maybe let people do other stuff with it as well.
files.find_files = function(opts) files.find_files = function(opts)
local find_command = (function() local find_command = (function()
if opts.find_command then if opts.find_command then
if type(opts.find_command) == "function" then
return opts.find_command(opts)
end
return opts.find_command return opts.find_command
elseif 1 == vim.fn.executable "fd" then elseif 1 == vim.fn.executable "fd" then
return { "fd", "--type", "f" } return { "fd", "--type", "f" }

View File

@@ -77,7 +77,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.files").grep_s
--- Search for files (respecting .gitignore) --- Search for files (respecting .gitignore)
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer) ---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer)
---@field find_command table: command line arguments for `find_files` to use for the search, overrides default: config ---@field find_command function|table: cmd to use for the search. Can be a fn(opts) -> tbl (default: autodetect)
---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command) ---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command)
---@field hidden boolean: determines whether to show hidden files or not (default: false) ---@field hidden boolean: determines whether to show hidden files or not (default: false)
---@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)