feat: add search_dirs opt to builtin.find_files to search from multiple dirs (#237)
This commit is contained in:
committed by
GitHub
parent
205790285b
commit
b5ff9de13d
@@ -57,16 +57,46 @@ end
|
||||
-- Support `find` and maybe let people do other stuff with it as well.
|
||||
files.find_files = function(opts)
|
||||
local find_command = opts.find_command
|
||||
local search_dirs = opts.search_dirs
|
||||
|
||||
if search_dirs then
|
||||
for k,v in pairs(search_dirs) do
|
||||
search_dirs[k] = vim.fn.expand(v)
|
||||
end
|
||||
end
|
||||
|
||||
if not find_command then
|
||||
if 1 == vim.fn.executable("fd") then
|
||||
find_command = { 'fd', '--type', 'f' }
|
||||
if search_dirs then
|
||||
table.insert(find_command, '.')
|
||||
for _,v in pairs(search_dirs) do
|
||||
table.insert(find_command, v)
|
||||
end
|
||||
end
|
||||
elseif 1 == vim.fn.executable("fdfind") then
|
||||
find_command = { 'fdfind', '--type', 'f' }
|
||||
if search_dirs then
|
||||
table.insert(find_command, '.')
|
||||
for _,v in pairs(search_dirs) do
|
||||
table.insert(find_command, v)
|
||||
end
|
||||
end
|
||||
elseif 1 == vim.fn.executable("rg") then
|
||||
find_command = { 'rg', '--files' }
|
||||
if search_dirs then
|
||||
for _,v in pairs(search_dirs) do
|
||||
table.insert(find_command, v)
|
||||
end
|
||||
end
|
||||
elseif 1 == vim.fn.executable("find") then
|
||||
find_command = { 'find', '.', '-type', 'f' }
|
||||
if search_dirs then
|
||||
table.remove(find_command, 2)
|
||||
for _,v in pairs(search_dirs) do
|
||||
table.insert(find_command, 2, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -77,7 +77,8 @@ do
|
||||
|
||||
mt_file_entry.cwd = cwd
|
||||
mt_file_entry.display = function(entry)
|
||||
local display, hl_group = entry.value
|
||||
local hl_group
|
||||
local display = path.make_relative(entry.value, cwd)
|
||||
if shorten_path then
|
||||
display = utils.path_shorten(display)
|
||||
end
|
||||
@@ -96,7 +97,11 @@ do
|
||||
if raw then return raw end
|
||||
|
||||
if k == "path" then
|
||||
return t.cwd .. path.separator .. t.value
|
||||
local retpath = t.cwd .. path.separator .. t.value
|
||||
if not vim.loop.fs_access(retpath, "R", nil) then
|
||||
retpath = t.value
|
||||
end
|
||||
return retpath
|
||||
end
|
||||
|
||||
return rawget(t, rawget(lookup_keys, k))
|
||||
|
||||
Reference in New Issue
Block a user