Convert Figma logo to code with AI

XAMPPRocky logotokei

Count your code, quickly.

10,883
529
10,883
149

Top Related Projects

19,272

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

6,488

Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

10,883

Count your code, quickly.

2,309

Count lines of code quickly.

Quick Overview

Tokei is a fast and accurate code statistics tool written in Rust. It can quickly analyze and report on the number of files, lines of code, comments, and blanks in various programming languages across multiple projects.

Pros

  • Extremely fast performance, especially for large codebases
  • Supports a wide range of programming languages (150+)
  • Provides detailed statistics including code, comments, and blank lines
  • Can generate output in various formats (e.g., JSON, YAML, TOML)

Cons

  • Limited customization options for ignoring specific files or directories
  • May not accurately detect all language-specific nuances in complex codebases
  • Lacks advanced features like code complexity analysis or duplicate code detection

Getting Started

To install Tokei, you can use one of the following methods:

  1. Using Cargo (Rust package manager):
cargo install tokei
  1. On macOS using Homebrew:
brew install tokei
  1. On Windows using Scoop:
scoop install tokei

To use Tokei, navigate to your project directory and run:

tokei

This will analyze the current directory and display statistics for all recognized languages. For more options and formats, use:

tokei --help

Competitor Comparisons

19,272

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

Pros of cloc

  • Supports a wider range of programming languages (over 500)
  • Offers more detailed reporting options, including XML and JSON output
  • Has built-in diff functionality for comparing multiple codebases

Cons of cloc

  • Generally slower performance, especially for large codebases
  • Written in Perl, which may be less familiar to some users
  • Less actively maintained compared to tokei

Code Comparison

cloc (Perl):

sub count_files {
    my ($ra_files) = @_;
    my %Results = ();
    foreach my $file (@{$ra_files}) {
        my ($language, $file_results) = analyze_file($file);
        $Results{$language}{$_} += $file_results->{$_} for keys %{$file_results};
    }
    return \%Results;
}

tokei (Rust):

pub fn count_files(files: &[PathBuf]) -> Result<Stats, Error> {
    let mut stats = Stats::new();
    for file in files {
        let language = Language::from_path(file)?;
        let file_stats = count_file(file)?;
        stats.merge(&file_stats);
    }
    Ok(stats)
}

Both tools aim to count lines of code, but tokei is generally faster and more modern, while cloc offers more extensive language support and reporting options.

6,488

Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

Pros of scc

  • Faster execution speed, especially for large codebases
  • More detailed output options, including complexity calculations
  • Built-in support for a wider range of file types

Cons of scc

  • Less actively maintained compared to tokei
  • Slightly more complex command-line interface
  • May consume more memory for very large projects

Code Comparison

scc:

fn main() {
    let args: Vec<String> = env::args().collect();
    let mut cli = Cli::new(&args).unwrap_or_else(|err| {
        eprintln!("{}", err);
        process::exit(1);
    });
}

tokei:

fn main() {
    let mut languages = Languages::new();
    let mut config = Config::default();
    let mut cli = Cli::from_args();
    cli.resolve_config_file(&mut config);
}

Both projects are written in Rust and serve similar purposes as code counting tools. scc focuses on speed and additional metrics, while tokei emphasizes simplicity and ease of use. The code snippets show their main functions, highlighting differences in CLI argument handling and configuration setup.

10,883

Count your code, quickly.

Pros of tokei

  • Fast and efficient code counting tool
  • Supports a wide range of programming languages
  • Provides detailed statistics and can generate reports in various formats

Cons of tokei

  • Limited customization options for output formats
  • May not accurately count code in some edge cases or complex project structures
  • Lacks advanced features like code complexity analysis

Code Comparison

Both repositories contain the same codebase, as they are the same project. Here's a sample of the main functionality from tokei:

pub fn get_statistics(paths: &[PathBuf], ignored: &[&str], config: &Config) -> Stats {
    let mut stats = Stats::new();
    for path in paths {
        stats.merge(&parse_path(path, ignored, config));
    }
    stats
}

This function is responsible for gathering statistics from the provided paths, considering ignored directories and configuration settings.

Summary

Tokei is a popular and efficient code counting tool with broad language support. While it excels in speed and simplicity, it may lack some advanced features found in more complex code analysis tools. The repository comparison shows that both links point to the same project, indicating no differences between them.

2,309

Count lines of code quickly.

Pros of loc

  • Written in Go, which may be more familiar to some developers
  • Simpler codebase, potentially easier to contribute to or modify
  • Faster execution for smaller codebases

Cons of loc

  • Less actively maintained (last commit over 3 years ago)
  • Fewer features and language support compared to tokei
  • Limited configuration options

Code Comparison

tokei:

pub fn count(config: &Config) -> Result<Stats, Error> {
    let mut stats = Stats::new();
    for path in &config.paths {
        stats.merge(&count_path(path, config)?);
    }
    Ok(stats)
}

loc:

func Count(paths []string, opts Options) ([]Lang, error) {
    var langs []Lang
    for _, path := range paths {
        l, err := countPath(path, opts)
        if err != nil {
            return nil, err
        }
        langs = append(langs, l...)
    }
    return langs, nil
}

Both projects implement similar functionality for counting lines of code across multiple paths. tokei uses Rust's Result type for error handling, while loc uses Go's multiple return values. tokei's implementation merges stats into a single object, whereas loc appends results to a slice of Lang structs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tokei (時計)

Mean Bean CI Help Wanted Lines Of Code Documentation Chocolatey Downloads dependency status Packaging status

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.

Translations

Example

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Language            Files        Lines         Code     Comments       Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 BASH                    4           49           30           10            9
 JSON                    1         1332         1332            0            0
 Shell                   1           49           38            1           10
 TOML                    2           77           64            4            9
───────────────────────────────────────────────────────────────────────────────
 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
───────────────────────────────────────────────────────────────────────────────
 Rust                   19         3416         2840          116          460
 |- Markdown            12          351            5          295           51
 (Total)                           3767         2845          411          511
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Total                  32         6745         4410         1506          829
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

API Documentation

Table of Contents

Features

  • Tokei is very fast, and is able to count millions of lines of code in seconds. Check out the 11.0.0 release to see how Tokei's speed compares to others.

  • Tokei is accurate, Tokei correctly handles multi line comments, nested comments, and not counting comments that are in strings. Providing an accurate code statistics.

  • Tokei has huge range of languages, supporting over 150 languages, and their various extensions.

  • 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 for how to get Tokei on your platform.

  • 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

Package Managers

Unix

# Alpine Linux (since 3.13)
apk add tokei
# Arch Linux
pacman -S tokei
# Cargo
cargo install tokei
# Conda
conda install -c conda-forge tokei
# Fedora
sudo dnf install tokei
# FreeBSD
pkg install tokei
# NetBSD
pkgin install tokei
# Nix/NixOS
nix-env -i tokei
# OpenSUSE
sudo zypper install tokei
# Void Linux
sudo xbps-install tokei

macOS

# Homebrew
brew install tokei
# MacPorts
sudo port selfupdate
sudo port install tokei

Windows

# Winget
winget install XAMPPRocky.tokei
# Scoop
scoop install tokei

Manual

Downloading

You can download prebuilt binaries in the releases section.

Building

You can also build and install from source (requires the latest stable Rust compiler.)

cargo install --git https://github.com/XAMPPRocky/tokei.git tokei

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.

$ 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.

$ tokei ./foo ./bar ./baz
$ tokei ./foo, ./bar, ./baz

Excluding folders

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.

$ tokei ./foo --exclude *.rs

Paths to exclude can also be listed in a .tokeignore file, using the same syntax 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

$ tokei ./foo --sort code

Outputting file statistics

By default tokei only outputs the total of the languages, and using --files flag tokei can also output individual file statistics.

$ 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.

  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
$ tokei ./foo --output json

Reading in stored formats

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.

$ tokei ./foo --input ./stats.json

Options

USAGE:
    tokei [FLAGS] [OPTIONS] [--] [input]...

FLAGS:
    -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.
    -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:
    -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.
    -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, 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 .

[![](https://tokei.rs/b1/github/XAMPPRocky/tokei)](https://github.com/XAMPPRocky/tokei).

Tokei's URL scheme is as follows.

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:

[![](https://tokei.rs/b1/github/XAMPPRocky/tokei?category=lines)](https://github.com/XAMPPRocky/tokei).

The server code hosted on tokei.rs is in XAMPPRocky/tokei_rs

Dockerized version

Tokei is available in a small alpine-based docker image, buildable through earthly:

earthly +docker

Once built, one can run the image with:

docker run --rm -v /path/to/analyze:/src tokei .

Or, to simply analyze the current folder (linux):

docker run --rm -v $(pwd):/src tokei .

Supported Languages

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, and you can read how to add and test your language in our CONTRIBUTING.md.

Abap
ActionScript
Ada
Agda
Alex
Alloy
Asn1
Asp
AspNet
Assembly
AssemblyGAS
ATS
Autoconf
AutoHotKey
Automake
AWK
Bash
Batch
Bazel
Bean
Bicep
Bitbake
BrightScript
C
Cabal
Cassius
Ceylon
CHeader
Cil
Clojure
ClojureC
ClojureScript
CMake
Cobol
CoffeeScript
Cogent
ColdFusion
ColdFusionScript
Coq
Cpp
CppHeader
Crystal
CSharp
CShell
Css
Cuda
CUE
Cython
D
D2
DAML
Dart
DeviceTree
Dhall
Dockerfile
DotNetResource
DreamMaker
Dust
Ebuild
EdgeDB
Edn
Elisp
Elixir
Elm
Elvish
EmacsDevEnv
Emojicode
Erlang
Factor
FEN
Fish
FlatBuffers
ForgeConfig
Forth
FortranLegacy
FortranModern
FreeMarker
FSharp
Fstar
GDB
GdScript
GdShader
Gherkin
Gleam
Glsl
Go
Graphql
Groovy
Gwion
Hamlet
Handlebars
Happy
Hare
Haskell
Haxe
Hcl
Hex
hledger
Hlsl
HolyC
Html
Hy
Idris
Ini
IntelHex
Isabelle
Jai
Janet
Java
JavaScript
Jq
Json
Jsx
Julia
Julius
KakouneScript
Kotlin
Lean
Less
Lingua Franca
LinkerScript
Liquid
Lisp
LLVM
Logtalk
Lua
Lucius
Madlang
Max
Makefile
Markdown
Mdx
Meson
Mint
Mlatu
ModuleDef
MonkeyC
MoonScript
MsBuild
Mustache
Nim
Nix
NotQuitePerl
NuGetConfig
Nushell
ObjectiveC
ObjectiveCpp
OCaml
Odin
OpenSCAD
OpenQASM
Org
Oz
Pascal
Perl
Perl6
Pest
Php
Po
Poke
Polly
Pony
PostCss
PowerShell
Processing
Prolog
Protobuf
PRQL
PSL
PureScript
Pyret
Python
Qcl
Qml
R
Racket
Rakefile
Razor
Renpy
ReStructuredText
RON
RPMSpecfile
Ruby
RubyHtml
Rust
Sass
Scala
Scheme
Scons
Sh
ShaderLab
Slang
Sml
Solidity
SpecmanE
Spice
Sql
SRecode
Stata
Stratego
Svelte
Svg
Swift
Swig
SystemVerilog
Slint
Tact
Tcl
Tex
Text
Thrift
Toml
Tsx
Twig
TypeScript
UMPL
UnrealDeveloperMarkdown
UnrealPlugin
UnrealProject
UnrealScript
UnrealShader
UnrealShaderHeader
UrWeb
UrWebProject
Vala
VB6
VBScript
Velocity
Verilog
VerilogArgsFile
Vhdl
VimScript
VisualBasic
VisualStudioProject
VisualStudioSolution
Vue
WebAssembly
Wolfram
Xaml
XcodeConfig
Xml
XSL
Xtend
Yaml
ZenCode
Zig
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 GitHub. If you have a GitHub account, please make your issues, and pull requests there.

Related Tools

  • tokei-pie: Render tokei's output to interactive sunburst chart.

Copyright and License

(C) Copyright 2015 by XAMPPRocky and contributors

See the graph 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-MIT for more information.