Silver Searcher:如何仅返回与模式匹配的文件夹中的结果?
我的文件结构是这样的:
A
G (want to ignore)
H (want to ignore)
X (contains files I want to search)
B
G (want to ignore)
H (want to ignore)
X (contains files I want to search)
C (want to ignore)
X (contains files I want to search)
我只想返回 X 是目录路径某处的结果。
看起来我可以使用 ag foo --ignore={G,H}
但要忽略的文件夹列表会非常长(几乎令人望而却步)。我通常想搜索所有文件夹,这样我就可以手动构建一个包含所有内容的全局忽略文件,并在我想忽略几乎所有内容时将其交换到位。
我发现这种语法可以让我在 A
和 B
的 X
文件夹中进行搜索,所以我很接近了!
ag foo */X
所以问题本质上是:如何才能拥有任意数量的正斜杠(0、1 或更多)?
My file structure is like this:
A
G (want to ignore)
H (want to ignore)
X (contains files I want to search)
B
G (want to ignore)
H (want to ignore)
X (contains files I want to search)
C (want to ignore)
X (contains files I want to search)
I want to only return results where X is somewhere the directory path.
It looks like I could use ag foo --ignore={G,H}
but the list of folders to ignore would be very (almost prohibitively) long. I normally want to search in ALL of the folders so I could manually construct a global ignore file with everything and swap it in place when I want to ignore mostly everything.
I found that this syntax lets me search within A
and B
's X
folder so I'm close!
ag foo */X
So the question is essentially: How can I have an arbitrary number of forward slashes (0, 1, or more)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单
ag
命令是不够的,我不认为这仅通过
ag
(银搜索器)命令。您需要以某种方式从整个目录树中过滤输入文件,并根据x
目录名称过滤。我会按照这些方式做一些事情:
它做什么?
命令在:
执行,然后通过
ag
搜索输出。tree -dfi
...打印整个路径(dir and files)您要搜索-d
...仅打印目录-f
...打印每个文件的完整路径前缀-i
...跳过输出中的空格(尝试尽可能处理)ag'\/x。*'
...搜索路径中的目录/x
(随后发生的任何字符0或多次) - 使用任何将选择要搜索的目录的REGEXP。中具有可搜索的输出(您可以以任何方式重定向)
Simple
ag
command is not enoughI don't think this simply just via
ag
(The silver searcher) command only. You need to somehow filter the input files from the whole directory tree, filtered based onX
directory name.I would do something along these lines:
What it does?
The command in:
is executed and the output is then searched via
ag
.tree -dfi
... prints the whole path (dir and files) you want to search-d
... prints only directories-f
... prints full path prefix for each file-i
... skips spaces in the output (tries to be as processable as possible)ag '\/X.*'
... searches for the directory/X
within the path (followed by any character present 0 or many times) - use any regexp which will select the directory you want to search in.ag 'search\sstring'
... searches for the 'search string' string within the filtered pathless
is there for you to have searchable output (you can redirect any way you want)