- Posted on
- • Artificial Intelligence
Artificial Intelligence Documentation with Ollama
- Author
-
-
- User
- linuxbash
- Posts by this author
- Posts by this author
-
Artificial Intelligence Documentation with Ollama: Turn Bash and Code into Clear Docs
Ever opened a repo and thought, “This is great… but where are the docs?” The fastest code still stalls if your team can’t understand, adopt, or maintain it. Good documentation is a force multiplier—and now you can generate and maintain it locally, privately, and repeatably with AI using Ollama and a few Bash one-liners.
This post shows you how to build a local AI documentation workflow that:
Runs on your machine (no data leaves your box)
Plays nicely with Bash pipelines and Makefiles
Produces practical docs: READMEs, cheat sheets, API summaries, and more
Why use Ollama for documentation?
Local-first and private: Keep source code, logs, and constraints in-house with no external API calls.
Reproducible: Pin your model and prompts in scripts so outputs are consistent and reviewable.
Fast iteration in Bash: Pipe files, man pages, or git diffs directly into a model with one command.
Flexible models: Pick a general model for prose (e.g., mistral) or a code-focused model when needed.
Installation
You’ll need a few common CLI tools and Ollama. Commands are provided for apt (Debian/Ubuntu), dnf (Fedora/RHEL), and zypper (openSUSE).
1) Install prerequisites
- Debian/Ubuntu (apt):
sudo apt update
sudo apt install -y curl jq git ripgrep
- Fedora/RHEL (dnf):
sudo dnf install -y curl jq git ripgrep
- openSUSE (zypper):
sudo zypper refresh
sudo zypper install -y curl jq git ripgrep
2) Install Ollama (Linux)
curl -fsSL https://ollama.com/install.sh | sh
Start the server (choose one):
# Foreground
ollama serve
# Background for this session
nohup ollama serve >/tmp/ollama.log 2>&1 &
# If your system uses systemd and the installer created a user service:
systemctl --user enable --now ollama
Verify and pull a model:
ollama --version
ollama pull mistral
Quick smoke test:
ollama run mistral "Write a one-line README headline for a Bash project that syncs photos."
Tip: For deterministic or tighter outputs, you can lower temperature:
ollama run mistral -o temperature=0.1 "Explain rsync in three bullets."
Core recipes: 4 practical ways to generate and maintain docs
Below are bash-first workflows you can drop into any repo. Replace the model name if you prefer another.
1) Generate a crisp README.md from your repo
This pipeline grabs representative slices of your project’s files and asks the model to write a reader-friendly README. It won’t upload anything—everything stays local.
# Generate README.md using local files (trimmed for size)
MODEL=mistral
PROJECT_DIR=/path/to/project
(
cd "$PROJECT_DIR"
{
echo "You are a senior technical writer. Create a clear, concise README.md for this Bash-based project."
echo
echo "Requirements for the README:"
echo "- Start with a one-sentence value proposition."
echo "- Provide a 'Quickstart' with copy-paste commands."
echo "- List dependencies and configuration (env vars, files)."
echo "- Add 'How it works' at a high level."
echo "- Include Troubleshooting and FAQ with 3-5 bullets."
echo
echo "Use Markdown with headers, bullet lists, and fenced code blocks."
echo
echo "Below are trimmed file excerpts for context:"
git ls-files | head -n 40 | while read -r f; do
echo "----- BEGIN $f -----"
sed -n '1,120p' "$f" 2>/dev/null || true
echo "----- END $f -----"
echo
done
} | ollama run "$MODEL" -o temperature=0.2
) | tee "$PROJECT_DIR/README.md"
What this does:
Captures the first ~120 lines of the first 40 tracked files
Instructs the model with specific README structure
Streams output into README.md for review and commit
2) Turn a man page into a 1-page cheat sheet
Create concise, example-first docs for your most-used commands.
# Make a concise cheat sheet for a CLI tool (example: rsync)
MODEL=mistral
CMD=rsync
OUTDIR=docs/cheatsheets
mkdir -p "$OUTDIR"
man "$CMD" | col -bx | sed -n '1,400p' | \
awk 'BEGIN{print "Create a succinct cheat sheet for '"$CMD"'. Focus on 80/20 usage. Include syntax, common flags, and 3-5 practical examples. Use Markdown with headings and fenced code blocks.\n\nSOURCE:\n"} {print} END{print "\nEND SOURCE"}' | \
ollama run "$MODEL" -o temperature=0.1 \
| tee "$OUTDIR/${CMD}.md"
Adjust the sed -n '1,400p' window if the page is too long. Commit the generated Markdown to docs/.
3) Generate API docs for your Bash functions
Extract function signatures from a Bash file and produce Markdown docs with arguments, return codes, and examples.
# Generate Markdown API docs from a Bash source file
MODEL=mistral
SRC=./scripts/backup.sh
OUT=docs/api-backup.md
mkdir -p "$(dirname "$OUT")"
{
echo "You are documenting a Bash library."
echo "From the source below, produce a Markdown API reference with:"
echo "- Per-function sections (name, purpose, parameters, exit codes, example call)."
echo "- Keep code blocks short and runnable."
echo
echo "SOURCE FILE: $SRC"
echo "----- BEGIN SOURCE -----"
sed -n '1,500p' "$SRC"
echo "----- END SOURCE -----"
} | ollama run "$MODEL" -o temperature=0.2 \
| tee "$OUT"
Keep the source slice modest (e.g., first 500 lines). For larger files, chunk them or document per-module.
4) Make docs reproducible with Make
Codify your documentation flow so anyone can run the same steps locally or in CI.
- scripts/gen_readme.sh:
#!/usr/bin/env bash
set -euo pipefail
MODEL="${1:-mistral}"
{
echo "Write a high-quality README for this project with Quickstart, Configuration, How it works, and Troubleshooting."
echo
git ls-files | head -n 40 | while read -r f; do
echo "----- BEGIN $f -----"
sed -n '1,120p' "$f" 2>/dev/null || true
echo "----- END $f -----"
done
} | ollama run "$MODEL" -o temperature=0.2
- scripts/gen_cheatsheet.sh:
#!/usr/bin/env bash
set -euo pipefail
MODEL="${1:-mistral}"
CMD="${2:?usage: gen_cheatsheet.sh <model> <cmd>}"
man "$CMD" | col -bx | sed -n '1,400p' | \
awk 'BEGIN{print "Write a concise Markdown cheat sheet for '"$CMD"' with examples.\n\n"} {print}' | \
ollama run "$MODEL" -o temperature=0.1
- Makefile:
MODEL ?= mistral
docs/readme.md:
@./scripts/gen_readme.sh "$(MODEL)" > $@
docs/cheatsheets/rsync.md:
@mkdir -p docs/cheatsheets
@./scripts/gen_cheatsheet.sh "$(MODEL)" rsync > $@
docs: docs/readme.md docs/cheatsheets/rsync.md
.PHONY: docs
Now run:
make docs MODEL=mistral
Pin MODEL in your repo (or a .env) for consistency, and review diffs like any other code change.
Tips for reliable outputs
Choose the right model: General writing (mistral, llama3), code-oriented variants for API docs.
Control variability: Lower
temperature(e.g., 0.1–0.2) for crisper, repeatable docs.Trim inputs: Feed only relevant file slices; large prompts slow generation and may dilute accuracy.
Save prompts: Keep prompt text in scripts for version control and team reuse.
Optional remote host: Point to another machine running Ollama if needed:
export OLLAMA_HOST=127.0.0.1:11434
Conclusion and next steps
Good docs remove adoption friction, reduce support load, and make your work shine. With Ollama and Bash, you can bootstrap, review, and maintain high-quality documentation without sending code to third-party services.
Your move: 1) Install Ollama and pull a model. 2) Run Recipe #1 on a repo you care about. 3) Wire Recipes #2–#4 into a Makefile so docs stay in lockstep with code.
If this helped, turn one of your internal tools into a documented, shareable project today—and ship it with confidence.