2.8 KiB
cflat (c♭)
Make your C++ project fall flat.
What is this?
cflat takes your complex directory structure and exports it into a single text file. It merges your entire C/C++ project into one massive stream of code.
Note: It does not actually delete your folders. It just ignores them in the output. Your architecture is safe.
Why?
Civilized people keep files separate. You, apparently, need them together.
- AI Fodder: Feed your entire codebase to an LLM so it can hallucinate a fix for that segfault you've been ignoring.
- Code Reviews: Send a single 50,000-line file to your reviewer. Assert dominance.
- Grepping: Search for a string across the project instantly because you still haven't memorized how to use
grep -r. - Spite: Annoy your lead architect by rendering their carefully crafted folder structure irrelevant.
Features
- Recursive: It hunts down source files in every nested folder. Deep sub-directories are no longer safe places to hide bad code.
- Fake Elegance: It runs
clang-format(if installed) so your spaghetti code at least looks professional in the export. - Hygiene: It ignores
obj,bin,.git, and other binary garbage that nobody wants to read. - Self-Preservation: It automatically adds itself and the output file to
.gitignore. This prevents you from accidentally committing a 12MB text file. - Flexible: Run it on the current folder, a target folder, or exclude specific shameful directories.
Installation
Trusting random scripts from the internet is a key part of the developer experience.
curl -O https://git.alidavid.hu/david/cflat/raw/branch/main/cflat
Make it executable:
chmod +x cflat
Usage
Default Behavior: Run this in your project root to flatten everything.
./cflat
Target a specific folder:
./cflat ../my-other-project/
The "Denial" option (Exclusions): Exclude folders you don't want the world (or the AI) to see.
./cflat -e build -e node_modules -e "legacy_code"
⚠️ Wildcards (Important)
Your shell expands * before the script sees it. If you don't use quotes, the script will break.
# Good:
./cflat -e "*.tmp"
# Bad (The shell expands this and confuses the script):
./cflat -e *.tmp
Need help?
./cflat -?
Output
The script generates a file named cflat-export-YYYY-MM-DD.txt. It contains:
- Project Stats: How many lines of code you are dealing with.
- The Tree: A visual map of the directory structure.
- The Cast: A list of all classes and structs found.
- The Blob: The full content of every source file, stitched together.
Requirements
- OS: Linux or macOS. (Windows users: please use WSL).
- Shell: Bash.
- Optional:
clang-format: For code cleaning.
License
MIT