tokei/README.md

507 lines
12 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:33:11 +00:00
[![crates.io](https://img.shields.io/crates/d/tokei.svg)](https://crates.io/crates/tokei)
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/)
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
2019-07-05 07:16:26 +00:00
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
2020-03-21 14:56:17 +00:00
BASH 4 49 30 10 9
JSON 1 1214 1214 0 0
Markdown 4 1236 1236 0 0
Rust 19 3049 2224 431 394
Shell 1 49 38 1 10
TOML 1 79 68 0 11
2019-07-05 07:16:26 +00:00
-------------------------------------------------------------------------------
2020-03-21 14:56:17 +00:00
Total 30 5676 4810 442 424
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)
- [How to use Tokei](#how-to-use-tokei)
- [Options](#options)
- [Badges](#badges)
2017-03-17 14:04:30 +00:00
- [Plugins](#plugins)
- [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-03-21 20:52:53 +00:00
- Tokei is **very fast**, check out our [latest release](https://github.com/XAMPPRocky/tokei/releases/latest)
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.
- Tokei can output in multiple formats(**CBOR**, **JSON**, **TOML**, **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.
## Installation
2020-03-08 21:44:52 +00:00
### Package Managers
```console
# 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
# MacOS (Homebrew)
brew install tokei
# Nix/NixOS
nix-env -i tokei
# OpenSUSE
sudo zypper 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
2020-03-21 21:36:51 +00:00
cargo install --git https://github.com/XAMPPRocky/tokei.git
```
2020-03-08 21:44:52 +00:00
[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
this file in three different places. The current directory,your home directory,
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:09:09 +00:00
[configuration]: ./.tokeirc.example
#### 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
```
#### 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
JSON:
cargo install tokei --features json
CBOR:
cargo install tokei --features cbor
YAML:
cargo install tokei --features yaml
TOML:
cargo install tokei --features toml
```
**Currently supported formats**
- JSON `--output json`
- YAML `--output yaml`
- TOML `--output toml`
- CBOR `--output cbor`
```shell
$ tokei ./foo --output json
```
#### Reading in stored formats
2018-04-15 18:52:05 +00:00
Tokei can also take in the outputted formats added in the previous results to it's
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.
--no-ignore-parent Don't respect ignore files in parent directories.
--no-ignore-vcs Don't respect VCS ignore files.
-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 containing the word.
-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]
-t, --type <types> Filters output by language type, seperated by a comma. i.e. -t=Rust,Markdown
ARGS:
<input>... The input file(s)/directory(ies) 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)
2017-03-17 14:04:30 +00:00
## Plugins
Thanks to contributors tokei is now available as a plugin for some text editors.
- [Vim](https://github.com/vmchale/tokei-vim) by [vmchale](https://github.com/vmchale/)
## 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
Asn1
Asp
AspNet
Assembly
AssemblyGAS
2019-01-13 20:43:09 +00:00
Autoconf
AutoHotKey
2019-01-13 20:43:09 +00:00
Automake
Bash
Batch
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
D
Dart
DeviceTree
2020-05-19 15:55:38 +00:00
Dhall
Dockerfile
DotNetResource
DreamMaker
Dust
2019-01-13 20:43:09 +00:00
Edn
Elisp
Elixir
Elm
2019-01-13 20:43:09 +00:00
Elvish
EmacsDevEnv
Emojicode
Erlang
FEN
2019-01-13 20:43:09 +00:00
Fish
FlatBuffers
2019-01-13 20:43:09 +00:00
Forth
FortranLegacy
FortranModern
FreeMarker
FSharp
Fstar
GDB
GdScript
Gherkin
Glsl
Go
Graphql
Groovy
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
Haskell
Haxe
Hcl
Hex
Hlsl
HolyC
Html
Idris
Ini
IntelHex
Isabelle
Jai
Java
JavaScript
Json
Jsx
Julia
Julius
KakouneScript
Kotlin
Lean
Less
LinkerScript
2019-01-13 20:43:09 +00:00
Liquid
Lisp
LLVM
2019-01-13 20:43:09 +00:00
Logtalk
Lua
Lucius
Madlang
Makefile
Markdown
Meson
2018-03-08 17:34:27 +00:00
Mint
ModuleDef
MoonScript
MsBuild
Mustache
Nim
Nix
NotQuitePerl
ObjectiveC
ObjectiveCpp
OCaml
Odin
2019-01-13 20:43:09 +00:00
Org
Oz
Pascal
Perl
2019-01-13 20:43:09 +00:00
Perl6
Pest
Php
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
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
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
2019-01-13 20:43:09 +00:00
Zig
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.
## 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.