How to exclude multiple directories with Exuberant ctags?
Asked Answered
B

6

62

I have looked and tried to use exuberant ctags with no luck with what I want to do. I am on a Mac trying to work in a project where I want to exclude such directories as .git, node_modules, test, etc. When I try something like ctags -R --exclude=[.git, node_modules, test] I get nothing in return. I really only need to have it run in my core directory. Any ideas on how to accomplish this?

Burkhardt answered 13/9, 2014 at 3:54 Comment(1)
Possible duplicate of Excluding directories in Exuberant CTagsLudwigg
D
98

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

Dichogamy answered 13/9, 2014 at 4:8 Comment(9)
Ok, this did partially work. So I don't have to ask another question and give you the answer for this - is there a way to only include a directory and not have to do the exclude? All I need is my core directoryBurkhardt
I think you could simply name the directory you want, no? Like ctags -R your_dir. Or I don't understand what you mean.Dichogamy
Yeah when i try this it does not tag anything from the core directory. :-(Burkhardt
You could also cd to it and run ctags -RDichogamy
@Burkhardt first make a list of files you'd want tags for, then run ctags on this list only: find -name your-files -o -path your-path > list.txt; ctags -L list.txtKalliekallista
Say you excluded node_modules–but only want to include one package from the node_modules for ctags to map, is this possible?Killingsworth
I don't know how to do that in one run, but you could ctags -R --exclude=node_modules and then ctags -Ra node_modules/my_package to append the tags in my_package to the tag file.Dichogamy
I came here to find out where to add this info, im not seeing that here, or in the man snippet below. im on a file config.cson, and see a ctags empty object in there, is that where this info gets plugged in at? Ok, found that little sucker, its in File->settings->packages-Ctags->settings CmdArgs input box.Alicealicea
Be forewarned, i just broke ctags by adding the excludes there, see my bug report on atom/ctags. not sure how, but cant use ctags anymore until I get author help apparently.Alicealicea
C
51

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 [email protected] .

with the following in .ctagsignore:

dir1
dir2
dir3

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

Calebcaledonia answered 13/9, 2014 at 7:43 Comment(4)
Hmmm. upvoted as handy answer, but guess that makes me a bad person as I should have RTFM'ed instead of coming here!Nogas
My favorite way to RTFM is googling and hoping someone on SO explained TFM for me. Thanks!Ridotto
I realize this is an old thread and answer, but the @ i.e. [email protected] doesn't work (actually, it does, see my edit) EDIT: Classic rubber duck solution... make sure that the ignore file doesn't have directories that end with /Nuri
Thanks for the answer. IMHO things have changed and now it is more efficient to do a quick search online for a specific solution and then RTFM if you don't find it that way.Rapport
S
24

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.

Schelling answered 13/3, 2017 at 18:57 Comment(2)
Nifty use of shell brace expansion!Amplifier
Only works for shells that support brace expansion (e.g. Bash). Will not work for POSIX compliant shells or for Windows cmd.Brooksbrookshire
N
3

The other answers were straight to the point, and I thought a little example may help:

You should add an asterisk unix-like style to exclude the whole directory.

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

Nanette answered 20/4, 2020 at 9:21 Comment(0)
L
2

A bit late but following on romainl response, you could use your .gitignore file as a basis, you only need to remove any leading slashes from the file, like so:

sed "s/\///" .gitignore > .ctagsignore

ctags -R [email protected]
Liveryman answered 15/11, 2022 at 19:19 Comment(0)
I
-3

I really only need to have it run in my core directory.

Simply remove the -R (recursion) flag!!!

Infestation answered 8/2, 2021 at 17:40 Comment(1)
Assuming the core directory has no subdirectories?Hoboken

© 2022 - 2024 — McMap. All rights reserved.