Skip to content

Instantly share code, notes, and snippets.

@devlato
Last active November 14, 2025 02:21
Show Gist options
  • Save devlato/6c6c6f0ed45c3311ed508666d61ae41d to your computer and use it in GitHub Desktop.
Save devlato/6c6c6f0ed45c3311ed508666d61ae41d to your computer and use it in GitHub Desktop.
Why.sh — use Cursor CLI to explain what's wrong with the command
# Use Cursor Agent to explain what's wrong with the command
# usage:
# why curl --request POST ...
# echo "foo" | why
why() {
emulate -L zsh
setopt pipefail
local file stdout_file stderr_file stdin_file prompt cmd_desc
file=$(uuidgen) || return 1
stdout_file="/tmp/${file}-stdout" || return 1
stderr_file="/tmp/${file}-stderr" || return 1
stdin_file="/tmp/${file}-stdin" || return 1
# Capture stdin if there is any (pipeline / redirected input)
if [[ ! -t 0 ]]; then
cat > "$stdin_file"
else
: > "$stdin_file"
fi
if (( $# > 0 )); then
# There is a command to run: why curl ...
echo
echo "$@"
echo
if [[ -s "$stdin_file" ]]; then
# Forward captured stdin into the command
"$@" 1>"$stdout_file" 2>"$stderr_file" <"$stdin_file"
else
"$@" 1>"$stdout_file" 2>"$stderr_file"
fi
cmd_desc=$(command -v -- "$1" || printf '%s\n' "$1 (not found)")
else
# No command, just piped stdin: ... | why
: > "$stdout_file"
: > "$stderr_file"
cmd_desc="[no command given; analysing piped stdin]"
fi
echo "Thinking..."
prompt=$(cat <<EOF
Here is stdin, stdout, and stderr (any of them can be empty) of a shell command.
Command:
$*
<description>
$cmd_desc
</description>
<stdin>
$( [[ -s "$stdin_file" ]] && cat "$stdin_file" )
</stdin>
<stdout>
$( cat "$stdout_file" )
</stdout>
<stderr>
$( cat "$stderr_file" )
</stderr>
<path>
$PATH
</path>
Explain what is wrong (if anything) and how to fix it.
Use markdown.
Immediately exit after responding.
EOF
)
printf '%s\n' "$prompt" | cursor-agent -p --model sonnet-4.5 | glow -w 120 -l -s light
rm -f "$stdout_file" "$stderr_file" "$stdin_file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment