feat: add 'follow' opt to find_files (#530)

This will add possibility to follow symlinks
This commit is contained in:
Asbjørn Håland
2021-02-12 22:31:27 +01:00
committed by GitHub
parent 09d1e3a607
commit 1c5e42a6a5

View File

@@ -97,6 +97,7 @@ end
files.find_files = function(opts) files.find_files = function(opts)
local find_command = opts.find_command local find_command = opts.find_command
local hidden = opts.hidden local hidden = opts.hidden
local follow = opts.follow
local search_dirs = opts.search_dirs local search_dirs = opts.search_dirs
if search_dirs then if search_dirs then
@@ -109,6 +110,7 @@ files.find_files = function(opts)
if 1 == vim.fn.executable("fd") then if 1 == vim.fn.executable("fd") then
find_command = { 'fd', '--type', 'f' } find_command = { 'fd', '--type', 'f' }
if hidden then table.insert(find_command, '--hidden') end if hidden then table.insert(find_command, '--hidden') end
if follow then table.insert(find_command, '-L') end
if search_dirs then if search_dirs then
table.insert(find_command, '.') table.insert(find_command, '.')
for _,v in pairs(search_dirs) do for _,v in pairs(search_dirs) do
@@ -118,6 +120,7 @@ files.find_files = function(opts)
elseif 1 == vim.fn.executable("fdfind") then elseif 1 == vim.fn.executable("fdfind") then
find_command = { 'fdfind', '--type', 'f' } find_command = { 'fdfind', '--type', 'f' }
if hidden then table.insert(find_command, '--hidden') end if hidden then table.insert(find_command, '--hidden') end
if follow then table.insert(find_command, '-L') end
if search_dirs then if search_dirs then
table.insert(find_command, '.') table.insert(find_command, '.')
for _,v in pairs(search_dirs) do for _,v in pairs(search_dirs) do
@@ -127,6 +130,7 @@ files.find_files = function(opts)
elseif 1 == vim.fn.executable("rg") then elseif 1 == vim.fn.executable("rg") then
find_command = { 'rg', '--files' } find_command = { 'rg', '--files' }
if hidden then table.insert(find_command, '--hidden') end if hidden then table.insert(find_command, '--hidden') end
if follow then table.insert(find_command, '-L') end
if search_dirs then if search_dirs then
for _,v in pairs(search_dirs) do for _,v in pairs(search_dirs) do
table.insert(find_command, v) table.insert(find_command, v)
@@ -138,6 +142,7 @@ files.find_files = function(opts)
table.insert(find_command, { '-not', '-path', "*/.*" }) table.insert(find_command, { '-not', '-path', "*/.*" })
find_command = flatten(find_command) find_command = flatten(find_command)
end end
if follow then table.insert(find_command, '-L') 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