Posted on
Artificial Intelligence

Artificial Intelligence Documentation Projects

Author
  • User
    linuxbash
    Posts by this author
    Posts by this author

Automate Your Docs: AI-Powered Documentation Workflows on Linux (Bash-first Guide)

Your documentation is lying to your users. Not because you want it to—but because docs rot. Features ship, flags change, and that perfect README from three months ago is now a maze of half-truths. The good news: you can make large parts of documentation writing, reviewing, and refreshing repeatable from the command line.

This post shows how to build AI-assisted documentation workflows that slot right into your Bash toolchain. You’ll set up a local or remote AI backend, then wire it to common tasks like drafting README sections, generating release notes, converting support threads into FAQs, and translating docs. Everything is scriptable, reviewable, and automatable in CI.

Why AI for documentation on Linux?

  • Text-in, text-out fits Bash perfectly. With curl, jq, and pipes, you can steer AI models like any other CLI.

  • Faster first drafts, consistent tone. Keep humans in the loop to review and edit, but let AI handle the boilerplate.

  • Works offline with local models. If you can’t send code outside your network, run an open-source model locally (llama.cpp).

  • Reproducible. Prompts and scripts live in your repo. You can test, diff, and version them like code.

What you’ll build

  • A portable AI client function in Bash (works with remote APIs or a local llama.cpp server).

  • 3–5 practical workflows you can drop into any repo:

    • Draft README “Quickstart” sections from code.
    • Generate release notes from git history.
    • Turn support threads into an FAQ.
    • Translate docs to another language.
    • Optional: lint docs structure and ask AI for suggested fixes.

1) Install prerequisites

The following packages are used in the scripts: curl, jq, pandoc, ripgrep, git, and basic C/C++ build tools (for optional local models).

  • Debian/Ubuntu (apt):

    sudo apt update
    sudo apt install -y curl jq pandoc ripgrep git build-essential cmake
    
  • Fedora/RHEL/CentOS Stream (dnf):

    sudo dnf install -y curl jq pandoc ripgrep git gcc gcc-c++ make cmake
    
  • openSUSE (zypper):

    sudo zypper refresh
    sudo zypper install -y curl jq pandoc ripgrep git gcc gcc-c++ make cmake
    

2) Choose your AI backend

You can use either a remote API or a fully local model. The same Bash function below can talk to both.

Option A: Remote API (quick start)

You’ll need an API key from your provider. Export these environment variables:

export AI_BASE_URL="https://api.openai.com"          # or your provider's base URL
export AI_MODEL="gpt-4o-mini"                        # or another chat-capable model
export AI_API_KEY="sk-..."                           # your API key

Test connectivity:

curl -sS -H "Authorization: Bearer $AI_API_KEY" "$AI_BASE_URL/v1/models" | jq .

Option B: Local open-source model with llama.cpp

Build llama.cpp from source and run a local server with an OpenAI-compatible API.

  • Build llama.cpp:

    git clone https://github.com/ggerganov/llama.cpp.git
    cd llama.cpp
    make -j
    
  • Download a chat-tuned GGUF model (example: Mistral 7B Instruct). Ensure you comply with the model’s license.

    mkdir -p models
    cd models
    wget -O mistral-7b-instruct.Q4_K_M.gguf \
    https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q4_K_M.gguf
    cd ..
    
  • Start the server (default port 8080):

    ./server -m models/mistral-7b-instruct.Q4_K_M.gguf -c 4096
    
  • Point your client to the local server:

    export AI_BASE_URL="http://localhost:8080"
    export AI_MODEL="mistral-7b-instruct.Q4_K_M.gguf"
    unset AI_API_KEY   # llama.cpp server doesn't require a key by default
    
  • Sanity check:

    curl -sS "$AI_BASE_URL/v1/models" | jq .
    

Tip: For better performance on capable GPUs/CPUs, consult llama.cpp’s README flags (e.g., -ngl for GPU layers).


3) A portable Bash AI client

Drop this into scripts/ai.sh (and source it) to standardize calls:

#!/usr/bin/env bash
set -euo pipefail

# Required env:
#   AI_BASE_URL  e.g., https://api.openai.com or http://localhost:8080
#   AI_MODEL     e.g., gpt-4o-mini or mistral-7b-instruct.Q4_K_M.gguf
#   AI_API_KEY   optional (not needed for local llama.cpp server)

ai_chat() {
  local system_prompt="${1:-"You are a helpful technical writer for Linux docs."}"
  local user_prompt="${2:-}"
  local temperature="${3:-0.2}"
  local max_tokens="${4:-800}"

  if [[ -z "${AI_BASE_URL:-}" || -z "${AI_MODEL:-}" ]]; then
    echo "AI_BASE_URL and AI_MODEL must be set" >&2
    return 2
  fi

  local auth_header=()
  if [[ -n "${AI_API_KEY:-}" ]]; then
    auth_header=(-H "Authorization: Bearer ${AI_API_KEY}")
  fi

  local payload
  payload="$(jq -n \
    --arg model "$AI_MODEL" \
    --arg sp "$system_prompt" \
    --arg up "$user_prompt" \
    --argjson temp "$temperature" \
    --argjson maxtok "$max_tokens" \
    '{model: $model,
      temperature: $temp,
      max_tokens: $maxtok,
      messages: [
        {role:"system", content:$sp},
        {role:"user", content:$up}
      ]}')"

  curl -sS "${auth_header[@]}" \
    -H "Content-Type: application/json" \
    -d "$payload" \
    "$AI_BASE_URL/v1/chat/completions" \
    | jq -r '.choices[0].message.content'
}

Source it:

source scripts/ai.sh

4) Actionable workflows you can use today

Below are four real-world examples you can adapt. Each one keeps humans in the loop by producing drafts you can edit and commit.

A) Draft a README “Quickstart” from your code

Collect a concise context (top comments, usage, help text), then ask AI for a minimal Quickstart.

# Gather context from a Bash script and CLI help
ctx="$( { sed -n '1,120p' ./your_cli.sh; echo; ./your_cli.sh --help 2>/dev/null || true; } | head -c 20000 )"

prompt="$(
cat <<'EOF'
Produce a concise "Quickstart" section in Markdown for the tool described in the context.

- Include: brief description, installation, a minimal usage example, and a note on configuration.

- Do not invent flags that do not exist.

- Keep it under 200 lines.
EOF
)"

ai_chat \
  "You are an expert technical writer. Be accurate and succinct." \
  "Context:\n---\n$ctx\n---\nTask:\n$prompt" \
  0.2 900 \
| tee DRAFT_README_QUICKSTART.md

If you mention installation in the draft, add distro-specific commands explicitly. For example, if your tool depends on ripgrep and jq, include:

  • Debian/Ubuntu (apt):

    sudo apt update
    sudo apt install -y ripgrep jq
    
  • Fedora/RHEL/CentOS Stream (dnf):

    sudo dnf install -y ripgrep jq
    
  • openSUSE (zypper):

    sudo zypper refresh
    sudo zypper install -y ripgrep jq
    

Review and edit DRAFT_README_QUICKSTART.md, then merge into README.md.

B) Generate release notes from git commits

Turn conventional commits into human-readable release notes.

since="${1:-"v$(git describe --tags --abbrev=0 2>/dev/null || echo 0.0.0)"}"
log="$(git log "${since}.." --pretty=format:'%s' || true)"

ai_chat \
  "You are a release notes editor. Organize items by Features, Fixes, Performance, Docs, Chore." \
  "Convert these commit subjects into clear release notes. Keep bullets, include notable breaking changes.\n\n$log" \
  0.2 700 \
| tee DRAFT_RELEASE_NOTES.md

Pro tip: Gate this in CI to generate notes on tag creation.

C) Convert support threads into an FAQ

Aggregate extracted Q/A snippets from issues, emails, or chat exports.

# Example: collect lines prefixed with Q: and A: from a folder of txt/md
faq_ctx="$(rg -n --glob '!node_modules' '^(Q:|A:)' -H docs/support/ | head -c 20000)"

ai_chat \
  "You are a documentation editor. Produce a clear end-user FAQ." \
  "From the snippets below, generate an FAQ in Markdown:\n$faq_ctx\n\nRules:\n- Group similar questions.\n- Short, accurate answers.\n- Include command examples in fenced code blocks when relevant." \
  0.3 900 \
| tee DRAFT_FAQ.md

D) Translate a doc to another language

Keep code blocks intact; translate prose only.

doc="${1:-README.md}"
content="$(cat "$doc" | head -c 30000)"

ai_chat \
  "You are a professional technical translator. Keep code blocks unchanged; translate prose to Spanish." \
  "$content" \
  0.2 1200 \
| tee "DRAFT_${doc%.md}.es.md"

Optional improvement: use pandoc to normalize input and preserve structure:

pandoc -t gfm "$doc" | head -c 30000 | ai_chat \
  "Translate to Spanish; keep code fences unchanged; preserve headings." \
  "$(cat)" \
  0.2 1200

5) Bonus: A lightweight docs linter with AI suggestions

Combine simple structural checks with AI hints.

issues=()

# Check README has required sections
for section in "Quickstart" "Installation" "Usage" "Configuration" "License"; do
  if ! rg -q "^#* *$section" README.md; then
    issues+=("Missing section: $section")
  fi
done

# Check every command in code fences has a shell prompt or explicit shell
if rg -n '```(bash|sh)?$' -n README.md | rg -qv '```(bash|sh)'; then
  issues+=("Some code fences lack language hints (bash/sh)")
fi

if ((${#issues[@]})); then
  printf '%s\n' "${issues[@]}" | tee LINT_ISSUES.txt

  suggestions="$(ai_chat \
    "You are a documentation reviewer for Linux CLI tools." \
    "Given these README issues:\n$(printf '%s\n' "${issues[@]}")\n\nProvide specific, short fixes in Markdown. Include example snippets." \
    0.3 600)"

  echo "$suggestions" | tee LINT_SUGGESTIONS.md
  exit 1
else
  echo "Docs lint passed."
fi

Wire this into CI to produce actionable suggestions on PRs.


Guardrails and best practices

  • Always review AI output. Treat drafts as proposals, not truth.

  • Keep prompts in-repo. Version them, test them, and share across projects.

  • Be explicit about installation for users:

    • apt:
    sudo apt update
    sudo apt install -y curl jq pandoc ripgrep
    
    • dnf:
    sudo dnf install -y curl jq pandoc ripgrep
    
    • zypper:
    sudo zypper refresh
    sudo zypper install -y curl jq pandoc ripgrep
    
  • Privacy and licensing. Don’t send sensitive code to external APIs if that violates policy. Prefer local models for private code.

  • Token limits. Truncate context (e.g., head -c 20000) and focus prompts.

  • Caching. For repeated runs, cache AI responses keyed by prompt hash to save time and cost.


Conclusion and next steps

Documentation shouldn’t be a heroic effort every release. With a small Bash wrapper and an AI backend (remote or local), you can standardize the boring parts—drafting, summarizing, translating—while keeping human judgment where it matters.

Your next steps: 1) Install the prerequisites with your package manager (apt/dnf/zypper). 2) Pick a backend: quick remote API or local llama.cpp. 3) Add scripts/ai.sh and try one workflow (README Quickstart or release notes). 4) Iterate: tune prompts, add CI jobs, and build your team’s doc toolbox.

If this helped, turn one of your recurring doc chores into a 1-line script this week. Your future self (and your users) will thank you.