- Posted on
- • Artificial Intelligence
Artificial Intelligence Linux Productivity Hacks
- Author
-
-
- User
- linuxbash
- Posts by this author
- Posts by this author
-
Artificial Intelligence Linux Productivity Hacks: Supercharge Your Bash in 15 Minutes
If you’ve ever lost 30 minutes deciphering an opaque error message, hunting the right grep incantation, or wordsmithing a commit, you’ve felt the tax of context switching. What if AI sat inside your terminal and handled the drudgery—without leaving Bash? This post shows exactly how: lightweight, composable CLI patterns that bring AI to your shell, using tools available from your distro package manager and optional local models.
You’ll get:
A dead-simple
aifilter you can pipe anything into (logs, errors, snippets).3–5 practical hacks (commit messages, cheat sheets from man pages, describe→command).
Reproducible install and setup steps for apt, dnf, and zypper.
The value: You keep your CLI workflow while offloading explanation, summarization, and “do-what-I-mean” translation to AI—cloud or local.
Why AI in the shell is worth it
AI thrives on text. Your terminal is pure text. No context switching or GUI detours.
You already stream data with pipes. AI becomes another filter in your toolbelt (
... | ai "Summarize").Privacy/flexibility: use a cloud provider, or run a local model via Ollama. Switch by flipping an env var.
It’s incremental. You don’t need a new toolchain—just a couple of functions in
~/.bashrc.
Prerequisites (install with your package manager)
You’ll need curl, jq (to handle JSON), and optionally git and fzf.
- Debian/Ubuntu (apt)
sudo apt update
sudo apt install -y curl jq git fzf
- Fedora/RHEL/CentOS (dnf)
sudo dnf install -y curl jq git fzf
- openSUSE (zypper)
sudo zypper refresh
sudo zypper install -y curl jq git fzf
Choose your AI backend
You can use a cloud model (OpenAI-compatible) or a local model (Ollama). Pick one, or configure both and toggle via AI_PROVIDER.
Option A: Cloud (OpenAI-compatible)
Add to ~/.bashrc or ~/.profile:
export AI_API_KEY="YOUR_API_KEY"
export AI_API_BASE="https://api.openai.com/v1" # or another OpenAI-compatible endpoint
export AI_MODEL="gpt-4o-mini" # or your preferred model
# export AI_PROVIDER="openai" # default if unset
Option B: Local (Ollama)
Install Ollama:
curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl enable --now ollama
ollama pull llama3
Then add to ~/.bashrc:
export AI_PROVIDER="ollama"
export AI_MODEL="llama3" # or another local model you've pulled
Reload your shell after editing:
source ~/.bashrc
Drop-in: a universal ai filter for your shell
Copy this into ~/.bashrc (or ~/.bash_functions) and reload. It auto-detects AI_PROVIDER to call a cloud or local model.
ai() {
local prompt="$*"
local input
input="$(cat 2>/dev/null || true)"
if [ "${AI_PROVIDER:-openai}" = "ollama" ]; then
jq -n \
--arg model "${AI_MODEL:-llama3}" \
--arg p "$prompt" \
--arg i "$input" \
'{
model: $model,
messages: [{role:"user", content: ($p + ( ($i|length) > 0 ? "\n\nInput:\n" + $i : ""))}],
stream: false
}' \
| curl -sS -H "Content-Type: application/json" -d @- http://localhost:11434/api/chat \
| jq -r '.message.content // .error // "Error: no response"'
else
: "${AI_API_BASE:=https://api.openai.com/v1}"
if [ -z "${AI_API_KEY:-}" ]; then
echo "Error: Set AI_API_KEY (and optionally AI_API_BASE, AI_MODEL)." >&2
return 1
fi
jq -n \
--arg model "${AI_MODEL:-gpt-4o-mini}" \
--arg p "$prompt" \
--arg i "$input" \
'{
model: $model,
messages: [{role:"user", content: ($p + ( ($i|length) > 0 ? "\n\nInput:\n" + $i : ""))}]
}' \
| curl -sS -H "Content-Type: application/json" -H "Authorization: Bearer '"$AI_API_KEY"'" -d @- "$AI_API_BASE/chat/completions" \
| jq -r '.choices[0].message.content // .error.message // "Error: no response"'
fi
}
Test it:
printf "Line one\nLine two with error code 13\n" | ai "Summarize and suggest likely causes."
5 actionable AI hacks for your Linux workflow
1) Explain and fix errors on the spot
Pipe stderr into ai to turn cryptic output into steps you can act on.
- Build error:
make 2>&1 | ai "Explain the error and propose 2–3 concrete fixes. Include exact commands."
- Systemd hiccup:
journalctl -u nginx --since "1 hour ago" | ai "Summarize recurring errors, suspected root causes, and verification steps as bullets."
- Shell mishap:
some_command 2>&1 | ai "What failed and how do I fix it? Show minimal reproducible commands."
Why it works: error logs + AI = high-signal diagnosis without context switching to docs or search.
2) Auto-generate great Git commit messages
Drop this into ~/.bashrc:
ai-commit() {
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Not a git repository." >&2
return 1
fi
local diff
diff="$(git diff --staged)"
if [ -z "$diff" ]; then
echo "Nothing staged. Use: git add <files>" >&2
return 1
fi
local msg
msg="$(printf "%s" "$diff" | ai "Write a concise Conventional Commit message.
- Use type: feat, fix, docs, chore, refactor, test, perf, build, ci
- Imperative mood
- Title <= 72 chars
- Include a short body only if valuable")"
echo
echo "Proposed commit message:"
echo "------------------------"
echo "$msg"
echo "------------------------"
read -r -p "Use this message? [y/N] " ans
if [[ "$ans" =~ ^[Yy]$ ]]; then
git commit -m "$msg"
fi
}
Use it:
git add .
ai-commit
Why it works: You keep consistency and clarity while spending seconds, not minutes.
3) Turn man pages into practical cheat sheets
Memorizing flags is overrated. Ask for examples instead.
Add to ~/.bashrc:
cheat() {
if [ -z "$1" ]; then
echo "Usage: cheat <command>" >&2
return 1
fi
local page
page="$(man "$1" | col -bx 2>/dev/null | sed -n '1,200p')"
if [ -z "$page" ]; then
echo "No man page found for $1" >&2
return 1
fi
printf "%s\n" "$page" | ai "From this man page excerpt, produce a quick cheat sheet:
- 5–10 common examples
- Each with a one-line explanation
- Output as markdown bullets"
}
Example:
cheat tar
Why it works: You get runnable examples tailored to the tool at hand, instantly.
4) Describe→Command (with a safety prompt)
Let AI propose a one-liner, show you exactly what it will run, and only execute with your confirmation.
Add to ~/.bashrc:
ai-do() {
if [ $# -eq 0 ]; then
echo "Usage: ai-do <what you want to do>" >&2
return 1
fi
local task="$*"
local cmd
cmd="$(ai "You are a Bash expert. Output only one safe, POSIX-compliant Bash command (no explanations) to: $task" </dev/null | head -n 1)"
echo
echo "Proposed command:"
echo "-----------------"
echo "$cmd"
echo "-----------------"
read -r -p "Run this command? [y/N] " ans
if [[ "$ans" =~ ^[Yy]$ ]]; then
eval "$cmd"
fi
}
Examples:
ai-do list the 20 largest files under /var/log sorted by size
ai-do find all Python files modified in the last 24h
Safety note: Always review generated commands. This pattern keeps you in control.
5) Summarize long output into the signal you need
Anywhere you have “too much text,” squeeze it down.
- Kubernetes:
kubectl logs deploy/myapp -n prod | ai "Summarize anomalies, error frequencies, and a short remediation checklist."
- Performance:
dmesg | ai "Highlight I/O bottleneck clues and next profiling steps."
- Config review:
grep -R "TODO" -n src | ai "Group TODOs by area, propose priorities, and list 3 quick wins."
Why it works: You keep the raw power of CLI tools while AI extracts meaning.
Optional add-ons
Fuzzy confirmation with
fzf(installed above): pipe multiple AI-suggested commands and pick one to run.Store prompts as scripts: codify your best
aiprompts into tiny helpers (e.g.,ai-fix,ai-summarize-logs).
Troubleshooting
Command not found: ensure functions are in a sourced file and
source ~/.bashrc.JSON errors: verify
jqis installed and your API env vars are correct.Local models: confirm Ollama is running:
systemctl status ollama
curl -s http://localhost:11434/api/tags
Conclusion and next step
You don’t need a new IDE to get AI superpowers—just a few shell functions:
Install the prerequisites with your package manager.
Pick cloud or local models.
Drop in the
ai,ai-commit,cheat, andai-dohelpers.Start piping your terminal’s text into intelligence.
CTA:
Paste the functions into your
~/.bashrcnow, runsource ~/.bashrc, and try:dmesg | ai "Summarize warnings."Evolve the prompts to match your stack.
Share your best prompt+pipe combos with your team and bake them into scripts.
Your terminal just got smarter—without leaving Bash.