DEV Community

Cover image for ๐Ÿค– Teaching the Cyborg to Document: Auto-Generated README.mdโ€™s with Style
raymonepping
raymonepping

Posted on

๐Ÿค– Teaching the Cyborg to Document: Auto-Generated README.mdโ€™s with Style

๐Ÿง  Why I Built This

Letโ€™s be honest: Documentation is usually an afterthought.
We ship the CLI, tag the release, maybe slap a README together โ€” and thenโ€ฆ forget about it.

But for a growing suite of modular, Homebrew-packaged Bash CLIs (like folder_tree, repository_backup, radar_loveโ€ฆ), that pattern falls apart fast. Outdated docs? Broken install steps? Yuck.

I wanted:

  • Docs that feel personal and consistent
  • Documentation that stays up-to-date by default
  • The ability to inject quotes, visuals, and folder trees โ€” without manual edits
  • To make the docs look good, becauseโ€ฆ tools that look good get used!

So I built: self_doc.sh.


TL;DR:
I automated my CLI documentation with Bash and modular templates, so every release ships with an up-to-date, beautiful README.md. Hereโ€™s how.


๐Ÿ› ๏ธ What Does self_doc.sh Do?

Auto-detects your CLIโ€™s binary, version, and metadata

Loads optional CLI-specific .cli.vars for easy customization

Uses modular Markdown templates (like readme_header.tpl, readme_quote.tpl, etc.)

Generates a clean, attractive README.md file โ€” ready to commit or publish

Falls back gracefully if visual tools like folder_tree arenโ€™t installed

Injects warnings and install hints automatically

Runs anywhere: No dependencies outside Bash + coreutils

Itโ€™s like a little CI pipeline for your docs โ€” but itโ€™s fast, local, and always in sync.


๐Ÿ“ฆ Template-Driven Docs

Instead of one big heredoc, self_doc.sh leverages a folder of template snippets:

tpl/
โ”œโ”€โ”€ readme_01_header.tpl
โ”œโ”€โ”€ readme_02_project.tpl
โ”œโ”€โ”€ readme_03_structure.tpl
โ”œโ”€โ”€ readme_04_body.tpl
โ”œโ”€โ”€ readme_05_quote.tpl
โ”œโ”€โ”€ readme_06_article.tpl
โ””โ”€โ”€ readme_07_footer.tpl
Enter fullscreen mode Exit fullscreen mode

Templates use smart placeholders:

{{CLI_NAME}}

{{VERSION}}

{{TAGLINE}}

{{FOLDER_TREE}} โ† replaced by a live tree view

Just reorder, remix, or reuse template files across projects. Zero lock-in.


๐ŸŒณ Smart Fallbacks: folder_tree vs. tree

If you have the folder_tree CLI installed, the README gets emoji-rich, beautiful output.
No folder_tree? It falls back to tree.

No tree either? You get this in your docs:

โŒ No tree tool available! Install either folder_tree or tree for full functionality.

No conditionals needed in your templates. No manual fixes. It Just Worksโ„ข.


โœจ Features at a Glance

  • โœ… Full CLI arg parsing (long + short flags)
  • ๐Ÿง  Auto-discovers CLI binary + version
  • ๐Ÿงฑ Modular template support (with fallback)
  • ๐Ÿ’ฌ Helpful errors if a template file is missing
  • ๐Ÿ“ Dynamic folder structure rendering
  • ๐Ÿšซ Dry-run and quiet modes for scripting/CI
  • ๐Ÿบ Homebrew-link and quote injection via .cli.vars
  • ๐Ÿงฝ Cleans emoji/ANSI codes from folder trees
  • ๐Ÿ”ง One-liner install suggestions if missing dependencies

๐Ÿ“„ Example Output

Hereโ€™s a real snippet from an auto-generated README:

๐ŸŒณ folder_tree  
CLI tool that visualizes and documents folder structures

Version: 1.0.5

> โš ๏ธ folder_tree CLI not found. This structure was generated using standard `tree` as fallback.
> To install folder_tree: `brew install raymonepping/folder-tree-cli/folder-tree-cli`

./
โ”œโ”€โ”€ bin/
โ”‚   โ””โ”€โ”€ folder_tree
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ folder_tree_utils.sh
โ”‚   โ””โ”€โ”€ self_doc.sh
โ””โ”€โ”€ tpl/
    โ””โ”€โ”€ readme_*.tpl
Enter fullscreen mode Exit fullscreen mode

You get context, usage, and install hints โ€” all without hand-writing Markdown.


๐Ÿ” Where I Use It

This one script now powers the docs for:

  • folder_tree โ€” structure-aware CLI
  • radar_love โ€” secret leak simulation for Vault Radar
  • repository_audit โ€” audit all the Git repos in your folders
  • repository_backup โ€” safe, modular, Homebrew-ready backup CLI

They all document themselves.
One command. No drift.


๐Ÿ“ˆ Zero-Drift Docs โ€” For Real

Once installed (Homebrew or manual), just point self_doc at your project. Examples:

# In a project folder with ./bin/my_cli:
self_doc

# To use templates from another repo:
self_doc -t ./x/tpl -f ./x/bin/y

Enter fullscreen mode Exit fullscreen mode

No guessing. No copying output.
Just a live README that always matches your code.

๐Ÿงช Real-World Value

This is more than just pretty READMEs:

  • Keeps your repos hygienic (especially when you have dozens)
  • Makes it easy for others to fork/contribute
  • Onboarding? Instant context.
  • Reinforces a culture of automation โ€” even for docs

๐Ÿงฐ Get Started!

Want to automate docs for your own Bash CLI project?
Clone it the old-school way:

curl -O https://raw.githubusercontent.com/raymonepping/folder_tree_cli/main/lib/self_doc.sh
chmod +x self_doc.sh
./self_doc.sh --tpl-dir ./tpl --outfile README.md
Enter fullscreen mode Exit fullscreen mode

Or, the Homebrew way (for easy updates):

brew install raymonepping/self-doc-gen-cli/self-doc-gen-cli
brew upgrade self-doc-gen-cli    # To update later
self_doc --help
Enter fullscreen mode Exit fullscreen mode

Homebrew keeps you up to date, everywhere.


๐Ÿ”š Final Thoughts

Docs donโ€™t have to be dull. Or manual. Or outdated.
With the right automation, theyโ€™re a first-class citizen of your CLI โ€” a mirror of your code.

self_doc.sh isnโ€™t just a helper script. Itโ€™s your CLIโ€™s reflection.

Soโ€ฆ

Build your CLIs. Let them document themselves.

Itโ€™s Bash, top to bottom. No YAML hell. No Node/Go runtimes.
Just you, your logic, and docs that never drift.


๐Ÿ“ฆ Grab the Script + Templates

Check it out on GitHub:
๐Ÿ‘‰ https://github.com/raymonepping/folder_tree_cli/tree/main/lib/self_doc.sh

Or just grab the raw script:
๐Ÿ‘‰ https://raw.githubusercontent.com/raymonepping/folder_tree_cli/main/lib/self_doc.sh

Feel free to adapt for your own projects!
Questions or feedback? Drop a comment below ๐Ÿ‘‡

Top comments (0)