tokei/README.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

590 lines
15 KiB
Markdown
Raw Normal View History

2016-11-28 12:26:11 +00:00
# Tokei ([時計](https://en.wiktionary.org/wiki/%E6%99%82%E8%A8%88))
2020-02-19 10:43:23 +00:00
[![Mean Bean CI](https://github.com/XAMPPRocky/tokei/workflows/Mean%20Bean%20CI/badge.svg)](https://github.com/XAMPPRocky/tokei/actions?query=workflow%3A%22Mean+Bean+CI%22)
2020-02-19 10:37:36 +00:00
[![Help Wanted](https://img.shields.io/github/issues/XAMPPRocky/tokei/help%20wanted?color=green)](https://github.com/XAMPPRocky/tokei/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
2020-02-19 10:33:11 +00:00
[![Lines Of Code](https://tokei.rs/b1/github/XAMPPRocky/tokei?category=code)](https://github.com/XAMPPRocky/tokei)
2017-08-10 08:02:52 +00:00
[![Documentation](https://docs.rs/tokei/badge.svg)](https://docs.rs/tokei/)
2022-05-22 05:08:06 +00:00
![](https://img.shields.io/crates/d/tokei?label=downloads%20%28crates.io%29)
![](https://img.shields.io/github/downloads/xampprocky/tokei/total?label=downloads%20%28GH%29)
![](https://img.shields.io/homebrew/installs/dy/tokei?color=brightgreen&label=downloads%20%28brew%29)
2020-03-22 10:35:48 +00:00
Tokei is a program that displays statistics about your code. Tokei will show the number of files, total lines within those files and code, comments, and blanks grouped by language.
2018-08-31 16:00:37 +00:00
### Translations
- [中文](https://github.com/chinanf-boy/tokei-zh#支持的语言)
2019-06-17 15:10:09 +00:00
## Example
2020-03-21 14:56:17 +00:00
```console
2022-05-20 05:40:38 +00:00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2019-07-05 07:16:26 +00:00
Language Files Lines Code Comments Blanks
2022-05-20 05:40:38 +00:00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2020-03-21 14:56:17 +00:00
BASH 4 49 30 10 9
2020-07-04 10:48:56 +00:00
JSON 1 1332 1332 0 0
2020-03-21 14:56:17 +00:00
Shell 1 49 38 1 10
2020-07-04 10:48:56 +00:00
TOML 2 77 64 4 9
2022-05-20 05:40:38 +00:00
───────────────────────────────────────────────────────────────────────────────
2020-07-04 10:48:56 +00:00
Markdown 5 1355 0 1074 281
|- JSON 1 41 41 0 0
|- Rust 2 53 42 6 5
|- Shell 1 22 18 0 4
(Total) 1471 101 1080 290
2022-05-20 05:40:38 +00:00
───────────────────────────────────────────────────────────────────────────────
2020-07-04 10:48:56 +00:00
Rust 19 3416 2840 116 460
|- Markdown 12 351 5 295 51
(Total) 3767 2845 411 511
2022-05-20 05:40:38 +00:00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2020-07-04 10:48:56 +00:00
Total 32 6745 4410 1506 829
2022-05-20 05:40:38 +00:00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2019-07-05 07:16:26 +00:00
```
2019-06-17 15:10:09 +00:00
2020-05-09 14:15:00 +00:00
## [API Documentation](https://docs.rs/tokei)
## Table of Contents
- [Features](#features)
- [Installation](#installation)
2020-03-08 21:44:52 +00:00
- [Package Managers](#package-managers)
- [Manual](#manual)
2020-05-19 16:11:18 +00:00
- [Configuration](#configuration)
- [How to use Tokei](#how-to-use-tokei)
- [Options](#options)
- [Badges](#badges)
- [Supported Languages](#supported-languages)
2016-06-11 01:10:58 +00:00
- [Changelog](CHANGELOG.md)
- [Common Issues](#common-issues)
- [Canonical Source](#canonical-source)
- [Copyright and License](#copyright-and-license)
## Features
2020-08-03 13:44:36 +00:00
- Tokei is **very fast**, and is able to count millions of lines of code in seconds.
Check out the [11.0.0 release](https://github.com/XAMPPRocky/tokei/releases/v11.0.0)
to see how Tokei's speed compares to others.
2018-06-16 14:55:09 +00:00
- Tokei is **accurate**, Tokei correctly handles multi line comments,
nested comments, and not counting comments that are in strings. Providing an
accurate code statistics.
2018-06-16 14:56:29 +00:00
- Tokei has huge range of languages, supporting over **150** languages, and
their various extensions.
2021-01-01 23:10:11 +00:00
- Tokei can output in multiple formats(**CBOR**, **JSON**, **YAML**)
allowing Tokei's output to be easily stored, and reused. These can also be
reused in tokei combining a previous run's statistics with another set.
- Tokei is available on **Mac**, **Linux**, and **Windows**. See [installation
instructions](#installation) for how to get Tokei on your platform.
2017-12-29 14:45:38 +00:00
- Tokei is also a **library** allowing you to easily integrate it with other
projects.
- Tokei comes with and without color. Set the env variable NO_COLOR to 1, and
it'll be black and white.
## Installation
2020-03-08 21:44:52 +00:00
### Package Managers
2020-10-23 13:22:27 +00:00
2022-08-13 19:42:01 +00:00
#### Unix
2020-03-08 21:44:52 +00:00
```console
# Alpine Linux (since 3.13)
apk add tokei
2020-03-08 21:44:52 +00:00
# Arch Linux
pacman -S tokei
# Cargo
cargo install tokei
2020-03-08 21:44:52 +00:00
# Conda
conda install -c conda-forge tokei
# Fedora
sudo dnf install tokei
# FreeBSD
pkg install tokei
2021-01-01 23:10:11 +00:00
# NetBSD
pkgin install tokei
2020-03-08 21:44:52 +00:00
# Nix/NixOS
nix-env -i tokei
# OpenSUSE
sudo zypper install tokei
# Void Linux
sudo xbps-install tokei
```
2020-10-23 13:22:27 +00:00
#### macOS
```console
# Homebrew
brew install tokei
# MacPorts
sudo port selfupdate
sudo port install tokei
```
#### Windows
```console
2023-07-16 08:31:15 +00:00
# Winget
winget install XAMPPRocky.tokei
# Scoop
2020-10-23 13:22:27 +00:00
scoop install tokei
```
2020-03-08 21:44:52 +00:00
### Manual
2020-03-08 21:44:52 +00:00
#### Downloading
You can download prebuilt binaries in the
[releases section](https://github.com/XAMPPRocky/tokei/releases).
2020-03-08 21:44:52 +00:00
#### Building
You can also build and install from source (requires the latest stable [Rust] compiler.)
```console
cargo install --git https://github.com/XAMPPRocky/tokei.git tokei
```
[rust]: https://www.rust-lang.org
2020-05-19 16:09:45 +00:00
## Configuration
Tokei has a [configuration] file that allows you to change default behaviour.
The file can be named `tokei.toml` or `.tokeirc`. Currently tokei looks for
2021-09-24 05:07:19 +00:00
this file in three different places. The current directory, your home directory,
2020-05-19 16:09:45 +00:00
and your configuration directory.
## How to use Tokei
#### Basic usage
This is the basic way to use tokei. Which will report on the code in `./foo`
and all subfolders.
```shell
$ tokei ./foo
```
2020-05-19 16:15:52 +00:00
[configuration]: ./tokei.example.toml
2020-05-19 16:09:09 +00:00
#### Multiple folders
To have tokei report on multiple folders in the same call simply add a comma,
or a space followed by another path.
2016-09-20 22:15:47 +00:00
```shell
$ tokei ./foo ./bar ./baz
```
```shell
$ tokei ./foo, ./bar, ./baz
```
#### Excluding folders
2018-04-15 18:52:05 +00:00
Tokei will respect all `.gitignore` and `.ignore` files, and you can use
the `--exclude` option to exclude any additional files. The `--exclude` flag has
the same semantics as `.gitignore`.
```shell
$ tokei ./foo --exclude *.rs
```
2021-05-09 18:28:50 +00:00
Paths to exclude can also be listed in a `.tokeignore` file, using the same
[syntax](https://git-scm.com/docs/gitignore) as .gitignore files.
#### Sorting output
By default tokei sorts alphabetically by language name, however using `--sort`
tokei can also sort by any of the columns.
`blanks, code, comments, lines`
```shell
$ tokei ./foo --sort code
```
2018-04-15 18:52:05 +00:00
#### Outputting file statistics
By default tokei only outputs the total of the languages, and using `--files`
flag tokei can also output individual file statistics.
```shell
$ tokei ./foo --files
```
#### Outputting into different formats
Tokei normally outputs into a nice human readable format designed for terminals.
There is also using the `--output` option various other formats that are more
useful for bringing the data into another program.
**Note:** This version of tokei was compiled without any serialization formats, to enable serialization, reinstall
tokei with the features flag.
```shell
ALL:
cargo install tokei --features all
CBOR:
cargo install tokei --features cbor
YAML:
cargo install tokei --features yaml
```
**Currently supported formats**
- JSON `--output json`
- YAML `--output yaml`
- CBOR `--output cbor`
```shell
$ tokei ./foo --output json
```
#### Reading in stored formats
2022-04-05 13:09:51 +00:00
Tokei can also take in the outputted formats added in the previous results to its
current run. Tokei can take either a path to a file, the format passed in as a
value to the option, or from stdin.
```shell
$ tokei ./foo --input ./stats.json
```
## Options
```
USAGE:
tokei [FLAGS] [OPTIONS] [--] [input]...
FLAGS:
2019-07-04 20:21:27 +00:00
-f, --files Will print out statistics on individual files.
-h, --help Prints help information
--hidden Count hidden files.
-l, --languages Prints out supported languages and their extensions.
--no-ignore Don't respect ignore files (.gitignore, .ignore, etc.). This implies --no-ignore-parent,
--no-ignore-dot, and --no-ignore-vcs.
--no-ignore-dot Don't respect .ignore and .tokeignore files, including those in parent directories.
--no-ignore-parent Don't respect ignore files (.gitignore, .ignore, etc.) in parent directories.
--no-ignore-vcs Don't respect VCS ignore files (.gitignore, .hgignore, etc.), including those in parent
directories.
2019-07-04 20:21:27 +00:00
-V, --version Prints version information
-v, --verbose Set log output level:
1: to show unknown file extensions,
2: reserved for future debugging,
3: enable file level trace. Not recommended on multiple files
OPTIONS:
2019-07-04 20:21:27 +00:00
-c, --columns <columns> Sets a strict column width of the output, only available for terminal output.
-e, --exclude <exclude>... Ignore all files & directories matching the pattern.
-i, --input <file_input> Gives statistics from a previous tokei run. Can be given a file path, or "stdin" to
read from stdin.
2019-07-04 20:21:27 +00:00
-o, --output <output> Outputs Tokei in a specific format. Compile with additional features for more format
support. [possible values: cbor, json, yaml]
-s, --sort <sort> Sort languages based on column [possible values: files, lines, blanks, code, comments]
2022-06-26 10:19:47 +00:00
-t, --type <types> Filters output by language type, separated by a comma. i.e. -t=Rust,Markdown
ARGS:
<input>... The path(s) to the file or directory to be counted.
```
## Badges
Tokei has support for badges. For example
2019-03-30 11:25:35 +00:00
[![](https://tokei.rs/b1/github/XAMPPRocky/tokei)](https://github.com/XAMPPRocky/tokei).
```
2019-03-30 11:25:35 +00:00
[![](https://tokei.rs/b1/github/XAMPPRocky/tokei)](https://github.com/XAMPPRocky/tokei).
```
Tokei's URL scheme is as follows.
```
2019-03-30 11:25:35 +00:00
https://tokei.rs/b1/{host: values: github|gitlab}/{Repo Owner eg: XAMPPRocky}/{Repo name eg: tokei}
```
By default the badge will show the repo's LoC(_Lines of Code_), you can also
specify for it to show a different category, by using the `?category=` query
string. It can be either `code`, `blanks`, `files`, `lines`, `comments`,
Example show total lines:
```
2019-03-30 11:25:35 +00:00
[![](https://tokei.rs/b1/github/XAMPPRocky/tokei?category=lines)](https://github.com/XAMPPRocky/tokei).
```
2019-03-30 11:25:35 +00:00
The server code hosted on tokei.rs is in [XAMPPRocky/tokei_rs](https://github.com/XAMPPRocky/tokei_rs)
## Dockerized version
Tokei is available in a small `alpine`-based docker image, buildable through [earthly](https://github.com/earthly/earthly):
```bash
earthly +docker
```
Once built, one can run the image with:
```bash
docker run --rm -v /path/to/analyze:/src tokei .
```
Or, to simply analyze the current folder (linux):
```bash
docker run --rm -v $(pwd):/src tokei .
```
## Supported Languages
2020-03-08 21:49:52 +00:00
If there is a language that you would to add to tokei feel free to make a pull
request. Languages are defined in [`languages.json`](./languages.json), and you can
read how to add and test your language in our [CONTRIBUTING.md](./CONTRIBUTING.md).
```
Abap
ActionScript
2016-09-20 22:15:47 +00:00
Ada
Agda
2019-01-13 20:43:09 +00:00
Alex
Alloy
Asn1
Asp
AspNet
Assembly
AssemblyGAS
ATS
2019-01-13 20:43:09 +00:00
Autoconf
AutoHotKey
2019-01-13 20:43:09 +00:00
Automake
2021-08-03 09:42:25 +00:00
AWK
Bash
Batch
Bazel
Bean
Bitbake
2019-01-13 20:43:09 +00:00
BrightScript
C
Cabal
Cassius
Ceylon
CHeader
Clojure
2019-01-13 20:43:09 +00:00
ClojureC
ClojureScript
CMake
Cobol
CoffeeScript
Cogent
ColdFusion
ColdFusionScript
Coq
Cpp
CppHeader
Crystal
CSharp
CShell
Css
Cuda
Cython
D
DAML
Dart
DeviceTree
2020-05-19 15:55:38 +00:00
Dhall
Dockerfile
DotNetResource
DreamMaker
Dust
Ebuild
EdgeDB
2019-01-13 20:43:09 +00:00
Edn
Elisp
Elixir
Elm
2019-01-13 20:43:09 +00:00
Elvish
EmacsDevEnv
Emojicode
Erlang
Factor
FEN
2019-01-13 20:43:09 +00:00
Fish
FlatBuffers
ForgeConfig
2019-01-13 20:43:09 +00:00
Forth
FortranLegacy
FortranModern
FreeMarker
FSharp
Fstar
GDB
GdScript
Gherkin
Gleam
Glsl
Go
Graphql
Groovy
2020-11-19 13:41:11 +00:00
Gwion
2019-01-13 20:43:09 +00:00
Hamlet
2016-09-20 22:15:47 +00:00
Handlebars
2019-01-13 20:43:09 +00:00
Happy
2024-05-02 15:54:53 +00:00
Hare
Haskell
Haxe
Hcl
Hex
Hlsl
HolyC
Html
Hy
Idris
Ini
IntelHex
Isabelle
Jai
2024-05-02 16:25:34 +00:00
Janet
Java
JavaScript
Jq
Json
Jsx
Julia
Julius
KakouneScript
Kotlin
Lean
Less
2024-05-02 15:58:45 +00:00
Lingua Franca
LinkerScript
2019-01-13 20:43:09 +00:00
Liquid
Lisp
LLVM
2019-01-13 20:43:09 +00:00
Logtalk
Lua
Lucius
Madlang
2024-05-02 15:54:22 +00:00
Max
Makefile
Markdown
Meson
2018-03-08 17:34:27 +00:00
Mint
2021-05-09 18:28:50 +00:00
Mlatu
ModuleDef
MoonScript
MsBuild
Mustache
Nim
Nix
NotQuitePerl
NuGetConfig
2023-05-11 08:32:33 +00:00
Nushell
ObjectiveC
ObjectiveCpp
OCaml
Odin
2024-05-02 16:24:37 +00:00
OpenQASM
2019-01-13 20:43:09 +00:00
Org
Oz
Pascal
Perl
2019-01-13 20:43:09 +00:00
Perl6
Pest
Php
2022-08-13 19:14:35 +00:00
Poke
Polly
Pony
PostCss
PowerShell
Processing
Prolog
Protobuf
PSL
PureScript
Python
Qcl
Qml
R
Racket
Rakefile
2016-09-20 22:15:47 +00:00
Razor
Renpy
ReStructuredText
RON
RPMSpecfile
Ruby
RubyHtml
Rust
Sass
Scala
2019-01-13 20:43:09 +00:00
Scheme
Scons
Sh
2022-08-22 17:34:49 +00:00
ShaderLab
2024-05-02 15:52:34 +00:00
Slang
Sml
2019-02-14 13:11:51 +00:00
Solidity
SpecmanE
Spice
Sql
SRecode
Stratego
Svelte
Svg
Swift
Swig
SystemVerilog
Tcl
Tex
Text
Thrift
Toml
Tsx
2019-01-13 20:43:09 +00:00
Twig
TypeScript
UMPL
UnrealDeveloperMarkdown
UnrealPlugin
UnrealProject
UnrealScript
UnrealShader
UnrealShaderHeader
UrWeb
UrWebProject
Vala
VB6
VBScript
Velocity
Verilog
VerilogArgsFile
Vhdl
VimScript
VisualBasic
VisualStudioProject
VisualStudioSolution
2019-01-13 20:43:09 +00:00
Vue
WebAssembly
Wolfram
Xaml
XcodeConfig
Xml
2019-01-13 20:43:09 +00:00
XSL
Xtend
Yaml
ZenCode
2019-01-13 20:43:09 +00:00
Zig
2024-05-02 16:23:04 +00:00
ZoKrates
Zsh
```
## Common issues
### Tokei says I have a lot of D code, but I know there is no D code!
This is likely due to `gcc` generating `.d` files. Until the D people decide on
a different file extension, you can always exclude `.d` files using the
`-e --exclude` flag like so
```
$ tokei . -e *.d
```
## Canonical Source
The canonical source of this repo is hosted on
2019-03-30 11:25:35 +00:00
[GitHub](https://github.com/XAMPPRocky/tokei). If you have a GitHub account,
please make your issues, and pull requests there.
## Related Tools
- [tokei-pie](https://github.com/laixintao/tokei-pie): Render tokei's output to
interactive sunburst chart.
## Copyright and License
2020-02-18 03:56:36 +00:00
(C) Copyright 2015 by XAMPPRocky and contributors
2020-01-27 14:52:25 +00:00
See [the graph](https://github.com/XAMPPRocky/tokei/graphs/contributors) for a full list of contributors.
Tokei is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See [LICENCE-APACHE](./LICENCE-APACHE), [LICENCE-MIT](./LICENCE-MIT) for more information.