How to exclude multiple directories with Exuberant ctags?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 20:35:46

The --exclude option does not expect a list of files. According to ctags's man page, "This option may be specified as many times as desired." So, it's like this:

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

Read The Fantastic Manual should always be the first step of any attempt to solve a problem.

From $ 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.

From the two first sentences you get:

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

which may be a bit verbose but that's what aliases and mappings and so on are for. As an alternative, you get this from the second paragraph:

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

with the following in .ctagsignore:

dir1
dir2
dir3

which works out to excluding those 3 directories without as much typing.

You can encapsulate a comma separated list with curly braces to handle multiples with one --exclude option:

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

This appears to only work for folders in the root of where you're issuing the command. Excluding nested folders requires a separate --exclude option.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!