fix: support find_command along with shorthand options (#1642)

This commit is contained in:
pedro757
2022-01-06 17:45:09 -04:00
committed by GitHub
parent 948f5adff2
commit f06dd06bb1

View File

@@ -148,7 +148,31 @@ end
-- TODO: Maybe just change this to `find`. -- TODO: Maybe just change this to `find`.
-- TODO: Support `find` and maybe let people do other stuff with it as well. -- 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 = opts.find_command local find_command = (function()
if opts.find_command then
return opts.find_command
elseif 1 == vim.fn.executable "fd" then
return { "fd", "--type", "f" }
elseif 1 == vim.fn.executable "fdfind" then
return { "fdfind", "--type", "f" }
elseif 1 == vim.fn.executable "rg" then
return { "rg", "--files" }
elseif 1 == vim.fn.executable "find" and vim.fn.has "win32" == 0 then
return { "find", ".", "-type", "f" }
elseif 1 == vim.fn.executable "where" then
return { "where", "/r", ".", "*" }
end
end)()
if not find_command then
print(
"You need to install either find, fd, or rg. "
.. "You can also submit a PR to add support for another file finder :)"
)
return
end
local command = find_command[1]
local hidden = opts.hidden local hidden = opts.hidden
local no_ignore = opts.no_ignore local no_ignore = opts.no_ignore
local follow = opts.follow local follow = opts.follow
@@ -160,9 +184,7 @@ files.find_files = function(opts)
end end
end end
if not find_command then if command == "fd" or command == "fdfind" or command == "rg" then
if 1 == vim.fn.executable "fd" then
find_command = { "fd", "--type", "f" }
if hidden then if hidden then
table.insert(find_command, "--hidden") table.insert(find_command, "--hidden")
end end
@@ -173,46 +195,14 @@ files.find_files = function(opts)
table.insert(find_command, "-L") table.insert(find_command, "-L")
end end
if search_dirs then if search_dirs then
if command ~= "rg" then
table.insert(find_command, ".") table.insert(find_command, ".")
end
for _, v in pairs(search_dirs) do for _, v in pairs(search_dirs) do
table.insert(find_command, v) table.insert(find_command, v)
end end
end end
elseif 1 == vim.fn.executable "fdfind" then elseif command == "find" then
find_command = { "fdfind", "--type", "f" }
if hidden then
table.insert(find_command, "--hidden")
end
if no_ignore then
table.insert(find_command, "--no-ignore")
end
if follow then
table.insert(find_command, "-L")
end
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 hidden then
table.insert(find_command, "--hidden")
end
if no_ignore then
table.insert(find_command, "--no-ignore")
end
if follow then
table.insert(find_command, "-L")
end
if search_dirs then
for _, v in pairs(search_dirs) do
table.insert(find_command, v)
end
end
elseif 1 == vim.fn.executable "find" and vim.fn.has "win32" == 0 then
find_command = { "find", ".", "-type", "f" }
if not hidden then if not hidden then
table.insert(find_command, { "-not", "-path", "*/.*" }) table.insert(find_command, { "-not", "-path", "*/.*" })
find_command = flatten(find_command) find_command = flatten(find_command)
@@ -229,8 +219,7 @@ files.find_files = function(opts)
table.insert(find_command, 2, v) table.insert(find_command, 2, v)
end end
end end
elseif 1 == vim.fn.executable "where" then elseif command == "where" then
find_command = { "where", "/r", ".", "*" }
if hidden ~= nil then if hidden ~= nil then
log.warn "The `hidden` key is not available for the Windows `where` command in `find_files`." log.warn "The `hidden` key is not available for the Windows `where` command in `find_files`."
end end
@@ -244,15 +233,6 @@ files.find_files = function(opts)
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
end end
end
if not find_command then
print(
"You need to install either find, fd, or rg. "
.. "You can also submit a PR to add support for another file finder :)"
)
return
end
if opts.cwd then if opts.cwd then
opts.cwd = vim.fn.expand(opts.cwd) opts.cwd = vim.fn.expand(opts.cwd)