Skip to content

Instantly share code, notes, and snippets.

@pnettto
Last active January 7, 2026 21:06
Show Gist options
  • Select an option

  • Save pnettto/112c74187c062a0e8af919c1be2c5357 to your computer and use it in GitHub Desktop.

Select an option

Save pnettto/112c74187c062a0e8af919c1be2c5357 to your computer and use it in GitHub Desktop.
Explainer shell script
#!/bin/bash
# This script was generated with Claude Code
set -euo pipefail
explain_command() {
local command="$1"
local api_key="${OPENAI_API_KEY:?Error: OPENAI_API_KEY not set}"
local response
response=$(curl -sf -X POST https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $api_key" \
-d @- <<EOF
{
"model": "gpt-4o-mini",
"messages": [{
"role": "system",
"content": "Explain the entire command line from start to finish in 2-3 clear sentences. Account for every component: the base command, all flags/options, arguments, operators (pipes, redirects, herestrings, substitutions), variables, quotes - everything visible in the command. Describe what happens step by step. Never use backticks or markdown."
}, {
"role": "user",
"content": "$command"
}],
"max_tokens": 100,
"temperature": 0.2
}
EOF
) || { echo "API request failed" >&2; return 1; }
jq -r '.choices[0].message.content' <<< "$response"
}
[[ $# -eq 0 ]] && { echo "Usage: $0 <command> [args...]" >&2; exit 1; }
explain_command "$*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment