Skip to content

alanrsoares/count_locs.go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐹 Count LOCs 🐹

A blazing-fast™ command-line tool to recursively count lines of code in a directory, supporting custom glob patterns for file matching. Built with Go, leveraging concurrency for speed and efficiency.

Features

  • Recursive directory traversal
  • Glob pattern matching for file extensions and paths
  • Concurrent processing for fast line counting
  • Breakdown of LOC by glob pattern (when multiple patterns are used)
  • Lightweight and easy to build and install

Installation

Prerequisites

  • Go installed

Steps

  1. Clone the repository:

    git clone git@github.com:yourusername/count_locs.git
    cd count_locs
  2. Download dependencies:

    go mod tidy
  3. Build the binary:

    go build -o count_locs
  4. (Optional) Install Globally:

    Move the binary to a directory that's in your PATH. For example:

    sudo mv count_locs /usr/local/bin/
  5. Verify Installation:

    count_locs --help

Usage

Basic Command

count_locs <directory> <glob-patterns>...

Examples

Count all Go files in the current directory:

count_locs . "**/*.go"

Count all Go, Python, and Markdown files in a project:

count_locs ./ "**/*.go" "**/*.py" "**/*.md"

Example Output

If multiple glob patterns are provided, you'll see a breakdown:

Breakdown of Lines of Code by Glob:
  **/*.go: 1200
  **/*.py: 800
  **/*.md: 150

Total:   2150 lines of code

Elapsed time: 150ms

If only one glob pattern is used, only the total is shown:

Total:   1500 lines of code

Elapsed time: 100ms

Development

Prerequisites

Ensure you have Go installed. You can download it from golang.org.

Build

Build the project with:

go build -o count_locs

Run Directly

You can also run the program without building a binary:

go run main.go <directory> <glob-patterns>...

Run Tests

If tests are provided, run:

go test ./...

Makefile Support

A Makefile is included for convenience. Here are some example targets:

  • Build the project:
    make build
  • Run tests:
    make test
  • Install globally:
    make install
  • Clean build artifacts:
    make clean
  • Run the binary:
    make run

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.cls
  2. Create a feature branch.
  3. Commit your changes.
  4. Push to your branch.
  5. Open a pull request.

License

This project is licensed under the Unlicense.

About

Blazing-fast™️ CLI tool to count lines of code with glob pattern support, built in Go 🐹

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published