中文 | English
gcloc is an open-source tool designed to count source code files and lines in various programming languages. It supports a wide range of languages and is easily extendable to include custom languages. Simple and easy to use, gcloc helps developers quickly understand their codebase and track changes over time.
This project builds upon the foundational work of hhatto's gocloc. We sincerely thank the original author for their contributions to the open-source community, which provided the basis for gcloc's further development.
- Language Support: Counts files, blank lines, comment lines, and code lines for multiple programming languages.
- Customizable: Add support for more languages as needed.
- High Performance: Utilizes concurrency for efficient file retrieval and analysis, making it fast even for large codebases.
- Output Formats: Supports multiple output formats, including default table view, XML, JSON, and Sloccount format.
- Filters: Include or exclude files and directories based on extensions, regex patterns, or specific languages.
- Detailed Statistics: Optionally report results for each source file.
-
Support for Git Repositories
- Analyze Git repositories directly without specifying a directory.
- Display statistics for the entire repository, including commit history.
-
Web Interface
- Create a web interface for gcloc to provide a user-friendly experience.
- Allow users to upload files or directories for analysis.
-
Support for Archive Files
- Analyze compressed files (e.g., .zip, .tar.gz) without manual extraction.
- Extract and analyze files on-the-fly to provide accurate statistics.
go install github.com/Scorpio69t/gcloc/app/gcloc@latest
Alternatively, download the precompiled binary from the Releases page.
gcloc [flags] PATH...
gcloc [command]
Analyze the current directory:
gcloc .
Sample Output:
$gcloc .
github.com/Scorpio69t/gcloc T=0.03 s (7318.7 files/s 2219353.8 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C++ Header 8 9494 3756 37956
C++ 28 3137 1752 13517
JSON 43 1 0 9368
...
Total 249 14710 7060 75508
-------------------------------------------------------------------------------
completion
: Generate the autocompletion script for your shell.help
: Display help information for a command.show-lang
: List all supported languages and their extensions.version
: Print the version number of gcloc.
Flag | Description |
---|---|
--by-file |
Report results for every encountered source file. |
--debug |
Dump debug log for developers. |
--exclude-ext |
Exclude file name extensions (comma-separated). |
--exclude-lang |
Exclude specific languages (comma-separated). |
--include-lang |
Include specific languages (comma-separated). |
--match |
Include files matching a regex pattern. |
--not-match |
Exclude files matching a regex pattern. |
--match-d |
Include directories matching a regex pattern. |
--not-match-d |
Exclude directories matching a regex pattern. |
--output-type |
Choose an output format: default , gcloc-xml , sloccount , json (default: default ). |
--skip-duplicated |
Skip duplicated files. |
--sort |
Sort results by name , files , blanks , comments , or codes (default: codes ). |
gcloc /path/to/code
gcloc --include-lang "C++,JSON" .
gcloc --exclude-ext "json,xml" .
gcloc --output-type json .
gcloc show-lang
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with detailed explanations.
This project is licensed under the MIT License.
Special thanks to all contributors who helped make gcloc a robust and reliable tool for source code analysis.