๐ง 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
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
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
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
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
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)