#!/usr/bin/env python3

from pathlib import Path
from collections import Counter

NO_EXTENSION = "[no extension]"

def main() -> None:
    counts: Counter[str] = Counter()

    for path in Path(".").rglob("*"):
        if not path.is_file():
            continue

        # pathlib treats ".gitignore" as having no suffix, which is usually
        # what you want for hidden files with no real extension.
        ext = path.suffix.lower() or NO_EXTENSION
        if ext == NO_EXTENSION:
            print(f"Non Extension: {path}")
        counts[ext] += 1

    for ext, count in sorted(counts.items(), key=lambda item: (-item[1], item[0])):
        print(f"{ext}: {count}")

if __name__ == "__main__":
    main()
