Skip to content

mojoaar/ccl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CCL - Count Code Lines

Version: 1.0.0
Author: Morten Johansen (mojoaar@atomicmail.io)
License: MIT

A cross-platform command-line tool to recursively count lines of code in a directory or a single file.

Features

  • Recursive directory traversal
  • Single file line counting
  • Exclude specific file types (defaults to excluding .md files)
  • JSON output support
  • Cross-platform (Windows, Linux, macOS)
  • Automatic binary file detection
  • Detailed breakdown by file type
  • Optional file path listing with -dirs flag

Installation

Build from source

go build -o ccl

Cross-platform builds

Use the provided build script:

PowerShell (Windows):

./build.ps1

Bash (Linux/macOS):

./build.sh

This will create binaries for all platforms in the bin/ directory:

  • ccl-windows-amd64.exe (Windows)
  • ccl-linux-amd64 (Linux)
  • ccl-darwin-amd64 (macOS Intel)
  • ccl-darwin-arm64 (macOS Apple Silicon)

Or build manually for specific platforms:

Windows:

GOOS=windows GOARCH=amd64 go build -o ccl.exe

Linux:

GOOS=linux GOARCH=amd64 go build -o ccl

macOS (Intel):

GOOS=darwin GOARCH=amd64 go build -o ccl

macOS (Apple Silicon):

GOOS=darwin GOARCH=arm64 go build -o ccl

Usage

Basic usage

Count lines in current directory (excludes .md files by default):

ccl

Count lines in a specific directory:

ccl /path/to/directory
# or
ccl -dir /path/to/directory

Count lines in a single file:

ccl -file /path/to/file.txt

Show version information:

ccl -version

Command-line Options

  • -dir <path> - Directory to scan for code files (default: current directory)

    ccl -dir /path/to/directory
  • -file <path> - Count lines in a specific file

    ccl -file main.go
  • -exclude <extensions> - Comma-separated list of file extensions to exclude (default: .md)

    ccl -exclude .md,.txt,.log
  • -dirs - Include individual file paths in the output

    ccl -dirs
  • -json - Output results in JSON format

    ccl -json
  • -version - Show version information

    ccl -version

Examples

Count all files including markdown:

ccl -exclude ""

Exclude multiple file types:

ccl -exclude .md,.txt,.json,.xml

Get JSON output for a specific directory:

ccl -json -dir /path/to/project

Show individual file paths:

ccl -dirs

Show file paths with JSON output:

ccl -dirs -json

Count lines in a single file (JSON):

ccl -file main.go -json

Output Examples

Text output (default)

Directory: X:/golang/ccl
Total files: 42
Total lines: 3521

Breakdown by file type:
  .go              15 files,     2103 lines
  .js              12 files,      892 lines
  .json             5 files,      215 lines
  .txt             10 files,      311 lines

Text output with file paths (-dirs)

Directory: X:/golang/ccl
Total files: 6
Total lines: 352

Breakdown by file type:
  .go                  1 files,      245 lines
  .gitignore           1 files,       28 lines
  (no extension)       1 files,       21 lines

Files:
  X:/golang/ccl/.gitignore                                           28 lines
  X:/golang/ccl/LICENSE                                              21 lines
  X:/golang/ccl/main.go                                             245 lines

JSON output

{
  "total_lines": 3521,
  "total_files": 42,
  "files_by_type": {
    ".go": 15,
    ".js": 12,
    ".json": 5,
    ".txt": 10
  },
  "lines_by_type": {
    ".go": 2103,
    ".js": 892,
    ".json": 215,
    ".txt": 311
  },
  "directory": "X:/golang/ccl"
}

JSON output with file paths (-dirs -json)

{
  "total_lines": 352,
  "total_files": 6,
  "files_by_type": {
    ".go": 1,
    ".gitignore": 1
  },
  "lines_by_type": {
    ".go": 245,
    ".gitignore": 28
  },
  "directory": "X:/golang/ccl",
  "files": [
    {
      "path": "X:/golang/ccl/.gitignore",
      "lines": 28
    },
    {
      "path": "X:/golang/ccl/main.go",
      "lines": 245
    }
  ]
}

Single file output (-file)

File: X:/golang/ccl/main.go
Lines: 299

Single file JSON output (-file -json)

{
  "file": "X:/golang/ccl/main.go",
  "lines": 299
}

Notes

  • Binary files are automatically detected and skipped (no warnings shown)
  • File paths in JSON output use forward slashes (/) for better cross-platform compatibility
  • The -exclude flag is ignored when using -file mode
  • Empty extension means files with no extension

License

MIT License

Copyright (c) 2025 Morten Johansen (mojoaar@atomicmail.io)

See LICENSE file for full license text.

About

Golang utility to count code lines in files

Resources

License

Stars

Watchers

Forks

Packages

No packages published