π§ 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)