Making it yours
By the end of this chapter you can set tokei's behaviour in a file it reads on every run — and you know the one fact about that file which explains most "tokei changed its mind" mysteries: it follows the folder you run from, not the folder you count.
The configuration file
Tokei looks for a file named
tokei.toml (or, failing that,
.tokeirc) in three places: your
operating system's config folder
(~/.config on Linux), your home
folder, and the folder you are
standing in — and the standing-in
file wins. That search order is
the project's documented behaviour;
the lab proved the local file's
effect directly, as follows.
The lab's fixtures/config folder
carries this tokei.toml:
# In this folder, docstrings count as comments.
treat_doc_strings_as_comments = true
Proof one: the docstring flip
Chapter 7 counted notes.py — the
docstring specimen — as 6 code,
0 comments, counting it from the
guide's root, where no config
file applies. Stand inside
fixtures/config, where the
tokei.toml sits, and count the
same folder:
./notes.py 7 1 5 1
./lib.rs 2 1 1 0
./tokei.toml 2 1 1 0
The docstring's five lines moved from code to comments; nothing else changed. (The third row is worth a glance: the config file is itself a file in the folder, and tokei counts it — one code line, one comment.)
Proof two: a types filter
Appending one line —
types = ["Rust"]
— and recounting left exactly one
file standing, lib.rs; the
Python file and the config file
itself both fell outside the
filter. The lab restored the
shipped tokei.toml afterwards;
the transcript
(tokei-lab/transcripts/t06-docstrings.txt)
shows both states.
What else the file accepts
The configuration's other keys
mirror the command-line switches —
hidden, the four no_ignore
switches, sort, and columns —
named here from the project's
configuration definition rather
than from transcripts; the two
keys above are the ones the lab
ran. Command-line flags and the
file are not rivals: the file sets
the standing behaviour for a
project, and a flag is how you
argue with it for one run.
The standing warning
Because the file is found from
where you stand, the same
command over the same tree can
give two answers from two
different shells. When a count
matters enough to quote, note the
directory you ran it from — or
better, run it from somewhere with
no tokei.toml in play, and say
so. Chapter 11 builds that habit
into a procedure.
Check: in fixtures/config, run
tokei --files . and confirm
notes.py reads 1 code and
5 comments; then run
tokei --files fixtures/config/notes.py
from the guide root and watch it
return to 6 and 0. If both land,
you have this chapter.