A tool that helps you know how many lines of code you have in your working directory.
Warning
I actually don't know how to make an installation script or put kloc on pypi and make it installable with pip. You may have to figure out adding to path and making it work as you want, etc.
-
Prerequisites:
- Python 3.6 or higher.
- Install
richlibrary:pip install rich
-
Clone the repository (or download the files):
-
git clone https://github.com/your-repo/kloc-python.git # (If this were a real repo) cd kloc-python
For now, ensure
kloc.py,kloc.config.json,.klocignore, andrequirements.txtare in your desired project directory. -
Install dependencies:
pip install -r requirements.txt
You can run the kloc.py script directly using Python.
python kloc.py <command> [options]This command helps you locate the kloc.config.json and .klocignore files.
-
Get
kloc.config.jsonpath:python kloc.py get --config
-
Get
.klocignorepath:python kloc.py get --ignore
-
Interactive selection:
python kloc.py get
This will prompt you to choose which file's path you want to see, allowing selection by number or arrow keys.
This command counts lines of code in the current directory based on various output formats.
-
Display total lines of code (oneline):
python kloc.py count -ol
-
Display lines of code for each file (tree format):
python kloc.py count -fi
-
Display lines of code for each language (table format):
python kloc.py count -ta
-
Interactive selection:
python kloc.py count
This will prompt you to choose your desired output format, allowing selection by number or arrow keys.
-
kloc.config.json(Optional): This file can be used to define custom language mappings, comment styles, and more. (Currently, this Python clone uses a basic internal language mapping. Future enhancements could include reading this file for more advanced configuration.)Example (not yet fully implemented in Python clone):
{ "languages": { "Python": { "extensions": [".py"], "comments": ["#"] }, "JavaScript": { "extensions": [".js", ".jsx"], "comments": ["//", "/*", "*/"] } } } -
.klocignore(Optional): Similar to.gitignore, this file specifies patterns for files and directories that should be ignored during the line counting process. Each line represents a pattern.Example:
node_modules/ .git/ *.log temp/
- Create a
.klocignorefile in your project root to exclude unwanted directories/files. - Run
python kloc.py count -tato see a summary of lines of code by language. - Run
python kloc.py count -fito inspect line counts per file.