Skip to content

Instantly share code, notes, and snippets.

@korchasa
Created February 3, 2024 03:27
Show Gist options
  • Save korchasa/26d77743d6ca5261a6ba15a53d7dffd7 to your computer and use it in GitHub Desktop.
Save korchasa/26d77743d6ca5261a6ba15a53d7dffd7 to your computer and use it in GitHub Desktop.
Shell command debug using aichat
#!/usr/bin/env bash
local command_text="$*"
command_output=$(eval "$command_text" 2>&1)
command_status=$?
echo "$command_output"
# Check if the command failed
if [ $command_status -ne 0 ]; then
print "==================================="
print "Explaining the error with aichat..."
print "==================================="
local prompt="An error occurred while executing the command. Explain its cause and suggest a way to correct it.\n"
prompt+="command: ${command_text}\n"
prompt+="output: ${command_output}\n"
aichat "${prompt}"
fi
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment