使用 Tokei 查看您的代码统计信息

了解有关项目编程语言等的详细信息。
47 位读者喜欢这个。
Top 4 JavaScript code editors

Opensource.com

最近,GitHub 添加了一个小指示器,显示项目的详细信息,包括项目使用的编程语言。在此之前,新的贡献者很难了解他们感兴趣的项目的这类信息。

这个添加功能很有用,但是如果你想知道关于本地存储库中项目的相同信息怎么办? 这就是 Tokei 派上用场的地方。 它是一个可以告诉你项目代码统计信息的工具,当你想要与精通不同语言的人一起构建项目时,它特别有用。

探索 Tokei

根据其 README,“Tokei 是一个显示有关您的代码的统计信息的程序。Tokei 将显示文件数量、这些文件中的总行数以及按语言分组的代码、注释和空白。” 其 v.12.1.0 版本的介绍 详细说明,“Tokei 是一款快速准确的代码分析 CLI 工具和库,可让您轻松快速地查看代码库中有多少空白行、注释行和代码行。” 它可以识别超过 150 种编程语言。

$ ./tokei ~/exa/src ~/Work/wildfly/jaxrs
==================
Language   Files Lines Code Comments Blank
Java        46    6135  4324  945     632
XML         23    5211  4839  473     224
---------------------------------
Rust
Markdown
-----------------------------------
Total 

安装 Tokei

在 Fedora 中安装 Tokei

$ sudo dnf install tokei

使用 Rust 的 Cargo 包管理器安装它

$ cargo install tokei

使用 Tokei

列出当前目录的代码统计信息

$ tokei
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Ada                    10         2840         1681          560          599
 Assembly                4         2508         1509          458          541
 GNU Style Assembly      4         2751         1528          748          475
 Autoconf               16         2294         1153          756          385
 Automake                1           45           34            0           11
 BASH                    4         1895         1602          133          160
 Batch                   2            4            4            0            0
 C                     330       206433       150241        23402        32790
 C Header              342        60941        24682        29143         7116
 CMake                  48         4572         3459          548          565
 C#                      9         1615          879          506          230
 C++                     5          907          599          136          172
 Dockerfile              2           16           10            0            6
 Fish                    1           87           77            5            5
 HTML                    1          545          544            1            0
 JSON                    5         8995         8995            0            0
 Makefile               10          504          293           72          139
 Module-Definition      12         1183         1046           65           72
 MSBuild                 1          141          140            0            1
 Pascal                  4         1443         1016          216          211
 Perl                    2          189          137           16           36
 Python                  4         1257          949          112          196
 Ruby                    1           23           18            1            4
 Shell                  15         1860         1411          222          227
 Plain Text             35        29425            0        26369         3056
 TOML                   64         3180         2302          453          425
 Visual Studio Pro|     30        14597        14597            0            0
 Visual Studio Sol|      6          655          650            0            5
 XML                     1          116           95           17            4
 YAML                    2           81           56           12           13
 Zsh                     1           59           48            8            3
-------------------------------------------------------------------------------
 Markdown               55         4677            0         3214         1463
 |- C                    1            2            2            0            0
 |- Rust                19          336          268           20           48
 |- TOML                23           61           60            0            1
 (Total)                           5076          330         3234         1512
-------------------------------------------------------------------------------
 Rust                  496       210966       188958         5348        16660
 |- Markdown           249        17676         1551        12502         3623
 (Total)                         228642       190509        17850        20283
===============================================================================
 Total                1523       566804       408713        92521        65570
===============================================================================
$

以下命令输出支持的语言和扩展名

$ tokei -l
ABNF
ABAP
ActionScript
Ada
Agda
Alex
Alloy
Arduino C++
AsciiDoc
ASN.1
ASP
ASP.NET
Assembly
GNU Style Assembly

如果您在两个文件上运行 tokei 并将它们的位置指定为参数,它会以后进先出的格式打印各个文件的统计信息

默认情况下,tokei 仅输出有关所用语言的数据,但使用 --files 标志可提供各个文件的统计信息

$ tokei ~/exa/src --files
===========================================================================================
 Language                              Files      Lines      Code 	      Comments     Blanks
===========================================================================================
 Rust                                  	54          9339        7070    	 400	   1869
 |- Markdown                            33          1306           0      	1165        141
 (Total)                                           10645        7070        1565       2010
-------------------------------------------------------------------------------------------
 /home/ssur/exa/src/theme/default_theme.rs           130         107           0         23
 /home/ssur/exa/src/output/render/times.rs            30          24           0          6
 /home/ssur/exa/src/output/render/users.rs            98          76           0         22
 /home/ssur/exa/src/output/render/size.rs            182         141           3         38
 /home/ssur/exa/src/output/render/octal.rs           116          88           0         28
 /home/ssur/exa/src/output/render/mod.rs              33          20           3         10
 /home/ssur/exa/src/output/render/inode.rs            28          20           0          8
 /home/ssur/exa/src/output/render/links.rs            87          65           0         22
 /home/ssur/exa/src/output/render/groups.rs          123          93           0         30
 |ome/ssur/exa/src/output/render/filetype.rs          31          26           0          5
 /home/ssur/exa/src/output/render/blocks.rs           57          40           0         17
 /home/ssur/exa/src/output/render/git.rs             108          87           0         21
 |/ssur/exa/src/output/render/permissions.rs         204         160           3         41
 /home/ssur/exa/src/output/grid.rs                    67          51           3         13
 /home/ssur/exa/src/output/escape.rs                  26          18           4          4
 /home/ssur/exa/src/theme/lsc.rs                     235         158          39         38
 /home/ssur/exa/src/options/theme.rs                 159         124           6         29
 /home/ssur/exa/src/options/file_name.rs              46          39           0          7
 /home/ssur/exa/src/options/flags.rs                  84          63           6         15
 /home/ssur/exa/src/fs/mod.rs                         10           8           0          2
 /home/ssur/exa/src/fs/feature/mod.rs                 33          25           0          8
-- /home/ssur/exa/src/output/time.rs ---------------------------------------------------------------
 |- Rust                                             215          170          5         40
 |- Markdown                                          28            0         25          3

结论

我发现使用 tokei 很容易了解有关我的代码统计信息的更多信息。 关于 tokei 的另一个好处是它可以作为一个库使用,这使得它可以很容易地集成到其他项目中。 访问 Tokei 的 Crate.io 页面Docs.rs 以了解有关其用法的更多信息。 如果您想参与其中,您还可以通过其 GitHub 存储库 为 Tokei 做出贡献。

您觉得 Tokei 有用吗? 请在下面的评论区告诉我们。

下一步阅读
Sudeshna is from Kolkata and currently working for the Red Hat Middleware team in Pune, India. She loves to explore different open source projects and programs. She started contributing to Open Source a couple of years back as an Hacktober Participant since then she has been an avid blogger at Dzone on Python and Data Science. She enjoys her free time stargazing and loves continental cuisine. She is an RHCSA and is working her way to RHCA.
Sudeshna 来自加尔各答,目前在印度浦那的 Red Hat 中间件团队工作。她喜欢探索不同的开源项目和程序。几年前,她作为 Hacktober 参与者开始为开源做贡献,此后她一直是 Dzone 上关于 Python 和数据科学的热心博主。她喜欢在空闲时间观星,并热爱欧洲大陆美食。

1 条评论

Hello Sudeshna Sur,我怎么强调这个工具的用处都不为过。它是一个增强版的 python 提示符。 它具有补全、历史记录、shell 功能等等。 请务必查看 https://mybkexperience.website/

Creative Commons License本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。
© . All rights reserved.