Skip to content

Flags that change the answer

By the end of this chapter you can change tokei's totals on purpose — letting hidden files in, excluding a file by name, switching the ignore files off one family at a time — and, more important, you can spot when a changed total is a changed filter rather than changed code.

Every experiment here runs over a specimen whose contents never change: three two-line Python files in flags/listing, each 1 code line and 1 comment (transcripts tokei-lab/transcripts/t04-flags.txt and t05-ignores.txt).

Hidden files: --hidden

Two of the three are ordinary; the third is .hidden.py. The default run never sees it:

default            2 files    4 lines    2 code    2 comments
--hidden           3 files    6 lines    3 code    3 comments

Nothing about the folder changed; the walker's first filter did.

Exclusion by name: -e

$ tokei --files .../flags/listing -e skipme.py

leaves only keep.py in the output. -e takes a pattern and can be given more than once. It is the surgical tool: one file or one directory, named by you, out.

The ignore files, and their three switches

Tokei respects the ignore files it finds on its walk. They come in families, and each family has its own off-switch:

  • .tokeignore and .ignore — switched by --no-ignore-dot. In flags/ignored, a .tokeignore naming muted.py leaves only counted.py in the count; --no-ignore-dot brings muted.py back.
  • VCS ignore files (.gitignore and kin) — switched by --no-ignore-vcs.
  • Ignore files in parent folders — switched by --no-ignore-parent.

--no-ignore switches all three families at once.

The fine print: a .gitignore needs its repository

The lab's flags/repo folder holds app.py, generated.py, and a .gitignore naming generated.py. Counted as it stands, both Python files appear — the .gitignore is inert, because the ignore rules tie it to a git repository and there is none. Run the shipped make-repo.sh (a plain git init), and the same count drops generated.py without a single file being edited. --no-ignore-vcs restores it.

This is the flag chapter's real lesson wearing a small example: tokei's answer depends on the state of the folder as much as on the files in it. A freshly cloned repository and the same tree copied without its .git can honestly produce different totals.

Check: count flags/listing three ways — default, --hidden, -e skipme.py — and predict each total before you run it (4, 6 and 2 lines). If all three land, you have this chapter.