【问题标题】:How to exclude multiple directories with Exuberant ctags?如何使用 Exuberant ctags 排除多个目录?
【发布时间】:2024-07-30 20:50:02
【问题描述】:

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

【问题讨论】:

标签: vim ctags exuberant-ctags


【解决方案1】:

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

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

【讨论】:

  • 好的,这确实部分有效。所以我不必再问另一个问题并给你答案 - 有没有办法只包含一个目录而不必排除?我只需要我的核心目录
  • 我认为您可以简单地命名您想要的目录,不是吗?喜欢ctags -R your_dir。或者我不明白你的意思。
  • 是的,当我尝试这样做时,它不会标记核心目录中的任何内容。 :-(
  • 你也可以cd 运行ctags -R
  • @pertrai1 首先列出您想要为其添加标签的文件,然后仅在此列表上运行 ctags:find -name your-files -o -path your-path > list.txt; ctags -L list.txt
【解决方案2】:

R阅读TF奇妙的M年度应该永远尝试解决问题的第一步。

来自$ 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 个目录而无需输入那么多内容。

【讨论】:

  • 嗯。被推荐为方便的答案,但我猜这让我成为一个坏人,因为我应该接受 RTFM 而不是来这里!
  • 我最喜欢的 RTFM 方式是谷歌搜索,希望 SO 上有人为我解释 TFM。谢谢!
  • 我意识到这是一个旧线程和答案,但@--exclude=@.ignorefiles 不起作用(实际上,它确实起作用,请参阅我的编辑)编辑:经典橡皮鸭解决方案......确保忽略文件没有以/ 结尾的目录
  • 感谢您的回答。恕我直言,事情已经发生了变化,现在在线快速搜索特定解决方案会更有效,如果找不到,则使用 RTFM。
【解决方案3】:

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

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

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

【讨论】:

  • 巧妙使用壳大括号扩展!
【解决方案4】:

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

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

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

【讨论】:

    【解决方案5】:

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

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

    【讨论】:

    • 假设核心目录没有子目录?