Created
February 3, 2024 03:27
-
-
Save korchasa/26d77743d6ca5261a6ba15a53d7dffd7 to your computer and use it in GitHub Desktop.
Shell command debug using aichat
This file contains 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
#!/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