tokei/README.md

467 lines
11 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))
2016-11-28 08:14:47 +00:00
[![Linux build status](https://img.shields.io/travis/Aaronepower/tokei.svg?branch=master)](https://travis-ci.org/Aaronepower/tokei)
[![Windows build status](https://ci.appveyor.com/api/projects/status/github/Aaronepower/tokei?svg=true)](https://ci.appveyor.com/project/Aaronepower/tokei)
[![](https://img.shields.io/crates/d/tokei.svg)](https://crates.io/crates/tokei)
[![](https://img.shields.io/github/issues-raw/Aaronepower/tokei.svg)](https://github.com/Aaronepower/tokei/issues)
[![](https://tokei.rs/b1/github/Aaronepower/tokei?category=code)](https://github.com/Aaronepower/tokei)
2017-08-10 08:02:52 +00:00
[![Documentation](https://docs.rs/tokei/badge.svg)](https://docs.rs/tokei/)
2018-01-02 16:57:43 +00:00
[![Donate using Liberapay](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/Aaronepower/donate)
2016-12-22 15:16:15 +00:00
Tokei is a program that displays statistics about your code. Tokei will show number of files, total lines within those files and code, comments, and blanks grouped by language.
2016-10-26 23:54:58 +00:00
## Example Output
2018-02-25 15:52:02 +00:00
This is tokei running on its own directory
2016-10-26 23:54:58 +00:00
2018-03-08 17:33:42 +00:00
[![asciicast](https://asciinema.org/a/d14m9g1d2cyo7wvrxh0z4ck6o.png)](https://asciinema.org/a/d14m9g1d2cyo7wvrxh0z4ck6o?autoplay=1)
2016-10-26 23:54:58 +00:00
2016-10-27 10:59:56 +00:00
## [Documentation](https://docs.rs/tokei)
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Automatic](#automatic)
2017-01-15 21:35:15 +00:00
- [Arch Linux](#arch-linux)
- [Cargo](#cargo)
- [Fedora](#fedora)
- [FreeBSD](#freebsd)
2018-02-15 21:04:25 +00:00
- [Homebrew](#homebrew)
- [Nix/NixOS](#nix/nixos)
- [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
- Tokei is **very fast**, below are the Tokei's times on a select few large
repositories, with a hot cache(_times are in seconds and measured using
2018-04-08 10:58:04 +00:00
[`hyperfine`](https://github.com/sharkdp/hyperfine) on macOS Sierra,
with 2.7 GHz Intel Core i7, results will vary_).
2018-06-02 16:23:45 +00:00
| Repository | Files | Lines | Real time |
|----------------|--------|------------|-----------|
| UnrealEngine 4 | 77,150 | 23,346,363 | 2.55s |
| DragonFlyBSD | 27,506 | 14,543,104 | 1.26s |
| Rust | 11,159 | 984,945 | 0.22s |
| CPython | 3,550 | 1,682,647 | 0.16s |
**Commit hashes used in tests**
**UnrealEngine 4** 08ee319f80ef47dbf0988e14b546b65214838ec4
**DragonFlyBSD** b3209e88d6ec0b2ca930d8b6878f781183a9894e
**Rust** 1b3d737716a4ae40709da627fc3e726ce539e405
**CPython** 00818c8ffd657f9ec727e366bfffd9c2135fa5ab
- 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-04-08 10:58:04 +00:00
- Tokei has huge range of languages, supporting over **130** 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
### Automatic
2017-01-15 21:35:15 +00:00
#### Arch Linux
```shell
2017-01-15 21:35:15 +00:00
$ pacman -S tokei
```
2017-01-15 21:35:15 +00:00
#### Cargo
```shell
$ cargo install tokei
```
#### Fedora
```shell
$ sudo dnf install tokei
```
#### FreeBSD
```shell
$ pkg install tokei
```
2018-02-15 21:04:25 +00:00
#### Homebrew
```shell
$ brew install tokei
```
#### Nix/NixOS
```shell
$ nix-env -i tokei
```
2017-01-15 21:35:15 +00:00
### Manual
You can download prebuilt binaries in the
[releases section](https://github.com/Aaronepower/tokei/releases), or create
from source.
```shell
$ git clone https://github.com/Aaronepower/tokei.git
$ cd tokei
$ cargo build --release
```
##### Linux
```
# sudo mv target/release/tokei /usr/local/bin
```
##### OSX
```
# sudo mv target/release/tokei /usr/local/bin/tokei
```
##### Windows
- Create a folder for tokei
- search for `env`
- open "edit your enviroment variables"
- edit `PATH`
- append folder path to the end of the string ie: `<path_stuff_here>;C:/tokei/;`
## 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
```
#### 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
CBOR:
cargo install tokei --features cbor
```
**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
```
tokei 7.0.1
Aaron P. <theaaronepower@gmail.com> + Contributors
A utility that allows you to count code, quickly.
USAGE:
tokei [FLAGS] [OPTIONS] [--] [input]...
FLAGS:
-f, --files Will print out statistics on individual files.
-h, --help Prints help information
-l, --languages Prints out supported languages and their extensions.
-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:
-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.
-o, --output <output> Outputs Tokei in a specific format. [values: cbor, json, toml, yaml]
-s, --sort <sort> Sort languages based on column [values: files, lines, blanks, code, comments]
ARGS:
<input>... The input file(s)/directory(ies) to be counted.
```
## Badges
Tokei has support for badges. For example
[![](https://tokei.rs/b1/github/Aaronepower/tokei)](https://github.com/Aaronepower/tokei).
```
[![](https://tokei.rs/b1/github/Aaronepower/tokei)](https://github.com/Aaronepower/tokei).
```
Tokei's URL scheme is as follows.
```
https://tokei.rs/{host: values: github|gitlab}/{Repo Owner eg: Aaronepower}/{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:
```
[![](https://tokei.rs/b1/github/Aaronepower/tokei?category=lines)](https://github.com/Aaronepower/tokei).
```
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
If there is a language that you want added, feel free to submit a pull request
with the following information. If you're unsure have a look at
[`languages.json`](./languages.json) to see how other languages are defined.
- Name of language
- File Extension(s)
- The comment syntax (_Does it have block comments? is it the same as C?_)
- The string literal syntax
```
ABAP
ActionScript
2016-09-20 22:15:47 +00:00
Ada
Alex
Agda
2016-09-20 22:15:47 +00:00
ASP
ASP.NET
Assembly
Autoconf
SH
AutoHotKey
BASH
FISH
Batch
C
C Header
C#
C Shell
Cabal
Cassius
Ceylon
Clojure
CMake
COBOL
CoffeeScript
Cogent
ColdFusion
ColdFusion CFScript
Coq
C++
C++ Header
CSS
Crystal
D
Dart
Device Tree
Dockerfile
Elixir
Elm
Emacs Development Environment
Emacs Lisp
Erlang
FEN
2016-09-20 22:15:47 +00:00
Forth
F*
F#
FORTRAN Legacy
FORTRAN Modern
GDScript
2016-10-15 15:47:59 +00:00
GLSL
Go
Groovy
Happy
2016-09-20 22:15:47 +00:00
Handlebars
Haskell
Haxe
HCL
2016-09-20 22:15:47 +00:00
HEX
HTML
Hamlet
Idris
2016-09-20 22:15:47 +00:00
Intel HEX
Isabelle
JAI
Java
JavaScript
JSON
JSX
Julia
Julius
Kotlin
Lean
LESS
LD Script
LISP
Lua
Lucius
Madlang
Makefile
Markdown
Meson
2018-03-08 17:34:27 +00:00
Mint
ModuleDef
Mustache
Nim
Nix
OCaml
Objective C
Objective C++
Org mode
Oz
Pascal
Perl
PHP
Polly
Processing
Prolog
Protocol Buffers
PSL Assertions
PureScript
Python
QCL
QML
R
Racket
Rakefile
2016-09-20 22:15:47 +00:00
Razor
ReStructuredText
Ruby
Ruby HTML
Rust
Sass
Scala
Scons
SRecode Template
Standard ML
Specman e
SPICE Netlists
SQL
2017-10-07 09:38:45 +00:00
SVG
Swift
SystemVerilog
TCL
TeX
Plain Text
TOML
TypeScript
Unreal Script
Ur/Web
Vala
Verilog
Verilog argument files
VHDL
Vim Script
Wolfram
Xaml
XML
Xtend
YAML
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
[GitHub](https://github.com/Aaronepower/tokei). If you have a GitHub account,
please make your issues, and pull requests there.
## Copyright and License
(C) Copyright 2015 by Aaron Power and contributors
See CONTRIBUTORS.md 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.