Last active
January 7, 2026 21:06
-
-
Save pnettto/112c74187c062a0e8af919c1be2c5357 to your computer and use it in GitHub Desktop.
Explainer shell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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