57

我已经查看并尝试使用旺盛的 ctags 来完成我想做的事情。我在 Mac 上尝试在一个项目中工作,我想排除 .git、node_modules、test 等目录。当我尝试类似的事情时,我什么ctags -R --exclude=[.git, node_modules, test]也得不到。我真的只需要让它在我的核心目录中运行。关于如何做到这一点的任何想法?

4

5 回答 5

86

--exclude选项不需要文件列表。根据ctags的手册页,“可以根据需要多次指定此选项。” 所以,它是这样的:

ctags -R --exclude=.git --exclude=node_modules --exclude=test

于 2014-09-13T04:08:59.120 回答
48

阅读《神奇手册》应该始终是任何尝试解决问题的第一步

来自$ man ctags

--exclude=[pattern]
  Add  pattern to a list of excluded files and directories. This option may
  be specified as many times as desired. For each file name  considered  by
  both the complete path (e.g. some/path/base.ext) and the base name  (e.g.
  base.ext)  of  the  file, thus allowing patterns which match a given file
  name irrespective of its path, or match only a specific path.  If  appro-
  priate  support is available from the runtime library of your C compiler,
  then pattern may contain the usual shell wildcards (not  regular  expres-
  sions)  common  on Unix (be sure to quote the option parameter to protect
  the wildcards from being expanded by the shell  before  being  passed  to
  ctags;  also be aware that wildcards can match the slash character, '/').
  You can determine if shell wildcards are available on  your  platform  by
  examining  the output of the --version option, which will include "+wild-
  cards" in the  compiled  feature  list;  otherwise,  pattern  is  matched
  against file names using a simple textual comparison.

  If  pattern begins with the character '@', then the rest of the string is
  interpreted as a file name from which to read exclusion patterns, one per
  line.  If  pattern  is  empty,  the list of excluded patterns is cleared.
  Note that at program startup, the default exclude list contains "EIFGEN",
  "SCCS",  "RCS", and "CVS", which are names of directories for which it is
  generally not desirable to descend while processing the --recurse option.

从你得到的前两个句子中:

$ ctags -R --exclude=dir1 --exclude=dir2 --exclude=dir3 .

这可能有点冗长,但这就是别名和映射等的用途。作为替代方案,您可以从第二段中得到:

$ ctags -R --exclude=@.ctagsignore .

与以下内容.ctagsignore

dir1
dir2
dir3

这可以排除这 3 个目录而无需输入太多内容。

于 2014-09-13T07:43:16.120 回答
21

您可以用花括号封装一个逗号分隔的列表,以使用一个--exclude选项处理多个:

ctags -R --exclude={folder1,folder2,folder3}

这似乎仅适用于您发出命令的根目录中的文件夹。排除嵌套文件夹需要单独的--exclude选项。

于 2017-03-13T18:57:29.043 回答
3

其他答案直截了当,我认为一个小例子可能会有所帮助:

您应该添加一个星号类 unix 样式来排除整个目录。

ctags -R --exclude={.git/*,.env/*,.idea/*} ./

于 2020-04-20T09:21:08.850 回答
-1

我真的只需要让它在我的核心目录中运行。

只需删除 -R (递归)标志!

于 2021-02-08T17:40:20.493 回答