Skip to content

Commit 751ee6b

Browse files
committed
feat(files): closes #84, add find_args config option
1 parent 406dd57 commit 751ee6b

File tree

4 files changed

+38
-293
lines changed

4 files changed

+38
-293
lines changed

lua/neo-tree/defaults.lua

+26
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ local config = {
9595
},
9696
},
9797
--find_command = "fd",
98+
---- you can specify extra args to pass to the find command.
99+
--find_args = {
100+
-- "--exclude", ".git",
101+
-- "--exclude", "node_modules"
102+
--},
103+
---- or use a function instead of list of strings
104+
--find_args = function(cmd, path, search_term, args)
105+
-- if cmd ~= "fd" then
106+
-- return args
107+
-- end
108+
-- --maybe you want to force the filter to always include hidden files:
109+
-- table.insert(args, "--hidden")
110+
-- -- but no one ever wants to see .git files
111+
-- table.insert(args, "--exclude")
112+
-- table.insert(args, ".git")
113+
-- -- or node_modules
114+
-- table.insert(args, "--exclude")
115+
-- table.insert(args, "node_modules")
116+
-- --here is where it pays to use the function, you can exclude more for
117+
-- --short search terms, or vary based on the directory
118+
-- if string.len(search_term) < 4 and path == "/home/cseickel" then
119+
-- table.insert(args, "--exclude")
120+
-- table.insert(args, "Library")
121+
-- end
122+
-- return args
123+
--end,
98124
search_limit = 50, -- max number of search results when using filters
99125
filters = {
100126
show_hidden = false,

lua/neo-tree/sources/filesystem/lib/filter_external.lua

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local Job = require("plenary.job")
44

55
local M = {}
66
local fd_supports_max_results = nil
7+
local unpack = unpack or table.unpack
78

89
local test_for_max_results = function(cmd)
910
if fd_supports_max_results == nil then
@@ -84,6 +85,16 @@ M.find_files = function(opts)
8485
return { "No search command found!" }
8586
end
8687

88+
if opts.find_args then
89+
if type(opts.find_args) == "string" then
90+
append(opts.find_args)
91+
elseif type(opts.find_args) == "table" then
92+
append(unpack(opts.find_args))
93+
elseif type(opts.find_args) == "function" then
94+
args = opts.find_args(cmd, path, term, args)
95+
end
96+
end
97+
8798
Job
8899
:new({
89100
command = cmd,

lua/neo-tree/sources/filesystem/lib/fs_scan.lua

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ M.get_items_async = function(state, parent_id, path_to_reveal, callback)
110110
limit = state.search_limit or 50,
111111
path = root.path,
112112
term = state.search_pattern,
113+
find_args = state.find_args,
113114
on_insert = function(err, path)
114115
if err and #err > 0 then
115116
log.error(err, path)

test.lua

-293
This file was deleted.

0 commit comments

Comments
 (0)