如何在Exuberant ctags中排除多个目录?

63

我已经查看并尝试使用兴高采烈的ctags,但没有达到我想要的效果。我正在Mac上尝试在一个项目中工作,我希望排除.git、node_modules、test等目录。当我尝试像ctags -R --exclude=[.git, node_modules, test]这样的命令时,什么也没有返回。我只需要它在我的核心目录中运行即可。有什么方法可以实现吗?


可能是Exuberant CTags中排除目录的重复问题 - Codie CodeMonkey
6个回答

95

--exclude选项不需要文件列表。根据ctags的手册页面,“可以指定此选项任意次数。” 因此,命令应该像这样:

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


好的,这部分是有效的。所以我不必再问另一个问题并为此提供答案 - 有没有一种方法只包括一个目录而不必排除其他的?我只需要我的核心目录。 - pertrai1
我认为你可以直接命名你想要的目录,对吧?像 ctags -R 你的目录。或者我不明白你的意思。 - aalazz
你也可以使用 cd 命令进入该目录并运行 ctags -R 命令。 - aalazz
2
@pertrai1 首先列出您想要标记的文件列表,然后仅在此列表上运行ctags:find -name your-files -o -path your-path > list.txt; ctags -L list.txt - m-ric
我来这里是想找到在哪里添加这些信息,但我没有在这里或下面的手册片段中看到。我正在一个名为config.cson的文件中,并且在其中看到了一个空的ctags对象,这是添加信息的地方吗?好的,找到那个小家伙了,在“文件”->“设置”->“包-Ctags”->“设置”中的“CmdArgs”输入框中。 - blamb
显示剩余4条评论

50

阅读 奇妙手册 应该是解决问题的第一步。

来自$ 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个目录。


4
嗯,我点赞了这个有用的回答,但我想这让我成为了一个坏人,因为我应该先阅读文档,而不是来这里问问题! - artfulrobot
11
我最喜欢的查阅文档方式是通过Google搜索,并希望Stack Overflow上有人为我解释文档。谢谢! - Subtlebot
1
我意识到这是一个旧的线程和答案,但是@--exclude=@.ignorefiles不起作用(实际上,它确实起作用,请参见我的编辑)编辑:经典的橡皮鸭解决方案...确保忽略文件没有以/结尾的目录。 - Samaursa
2
感谢您的回答。在我看来,事情已经改变了,现在更有效率的方法是在线快速搜索特定的解决方案,如果这样找不到,再去查阅文档。 - Tanausú González

24

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

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

看起来这只适用于您发出命令的位置根目录中的文件夹。要排除嵌套的文件夹,需要单独使用--exclude选项。


2
花括号扩展的妙用! - Tom Hale
1
仅适用于支持花括号扩展的shell(例如Bash)。不适用于符合POSIX标准的shell或Windows cmd。 - Lorem Ipsum

3
其他回答直截了当,我认为一个小例子可能会有所帮助:
您应该添加类似于Unix的星号以排除整个目录。
ctags -R --exclude={.git/*,.env/*,.idea/*} ./


1
有点晚了,但是继续跟随romainl的回答,你可以使用你的.gitignore文件作为基础,你只需要从文件中删除任何前导斜杠,就像这样:
sed "s/\///" .gitignore > .ctagsignore

ctags -R --exclude=@.ctagsignore

-3
我只需要它在我的核心目录中运行。
只需删除-R(递归)标志即可!

假设核心目录没有子目录? - Suraj Rao

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接