1
1
local vim = vim
2
2
local log = require (" neo-tree.log" )
3
3
local Job = require (" plenary.job" )
4
+ local utils = require (" neo-tree.utils" )
4
5
5
6
local M = {}
6
7
local fd_supports_max_results = nil
@@ -47,10 +48,21 @@ M.find_files = function(opts)
47
48
local limit = opts .limit or 200
48
49
local cmd = get_find_command (opts )
49
50
local path = opts .path
50
- local term = opts .term
51
+ local full_path_words = opts .find_by_full_path_words
52
+ local regex , glob = opts .term , opts .term
51
53
52
- if term ~= " *" and not term :find (" *" ) then
53
- term = " *" .. term .. " *"
54
+ if full_path_words then
55
+ local words = utils .split (glob , " " )
56
+ regex = " .*" .. table.concat (words , " .*" ) .. " .*"
57
+ else
58
+ if glob ~= " *" then
59
+ if glob :sub (1 ) ~= " *" then
60
+ glob = " *" .. glob
61
+ end
62
+ if glob :sub (- 1 ) ~= " *" then
63
+ glob = glob .. " *"
64
+ end
65
+ end
54
66
end
55
67
56
68
local args = {}
@@ -67,7 +79,12 @@ M.find_files = function(opts)
67
79
if not filters .respect_gitignore then
68
80
append (" --no-ignore" )
69
81
end
70
- append (" --glob" , term , path )
82
+ if full_path_words then
83
+ append (" --full-path" , regex )
84
+ else
85
+ append (" --glob" , glob )
86
+ end
87
+ append (path )
71
88
append (" --color" , " never" )
72
89
if fd_supports_max_results then
73
90
append (" --max-results" , limit )
@@ -78,9 +95,17 @@ M.find_files = function(opts)
78
95
if not filters .show_hidden then
79
96
append (" -not" , " -path" , " */.*" )
80
97
end
81
- append (" -iname" , term )
98
+ if full_path_words then
99
+ append (" -regextype" , " sed" , " -regex" , regex )
100
+ else
101
+ append (" -iname" , glob )
102
+ end
103
+ elseif cmd == " fzf" then
104
+ -- This does not work yet, there's some kind of issue with how fzf uses stdout
105
+ error (" fzf is not a supported find_command" )
106
+ append (" --no-sort" , " --no-expect" , " --filter" , opts .term ) -- using the raw term without glob patterns
82
107
elseif cmd == " where" then
83
- append (" /r" , path , term )
108
+ append (" /r" , path , glob )
84
109
else
85
110
return { " No search command found!" }
86
111
end
@@ -91,13 +116,15 @@ M.find_files = function(opts)
91
116
elseif type (opts .find_args ) == " table" then
92
117
append (unpack (opts .find_args ))
93
118
elseif type (opts .find_args ) == " function" then
94
- args = opts .find_args (cmd , path , term , args )
119
+ args = opts .find_args (cmd , path , glob , args )
95
120
end
96
121
end
97
122
123
+ log .info (cmd , args )
98
124
Job
99
125
:new ({
100
126
command = cmd ,
127
+ cwd = path ,
101
128
args = args ,
102
129
enable_recording = false ,
103
130
maximum_results = limit or 100 ,
@@ -114,7 +141,7 @@ M.find_files = function(opts)
114
141
opts .on_insert (err , line )
115
142
end
116
143
end ,
117
- on_exit = function (j , return_val )
144
+ on_exit = function (_ , return_val )
118
145
if opts .on_exit then
119
146
opts .on_exit (return_val )
120
147
end
0 commit comments