Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo raw response data when redirecting to file #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions chatgpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,17 @@ while $running; do
handle_error "$response"
response_data=$(echo "$response" | jq -r '.choices[].message.content')

echo -e "$OVERWRITE_PROCESSING_LINE"
# if glow installed, print parsed markdown
if command -v glow &>/dev/null; then
echo -e "${CHATGPT_CYAN_LABEL}"
echo "${response_data}" | glow -
if [ -t 1 ]; then
echo -e "$OVERWRITE_PROCESSING_LINE"
# if glow installed, print parsed markdown
if command -v glow &>/dev/null; then
echo -e "${CHATGPT_CYAN_LABEL}"
echo "${response_data}" | glow -
else
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w "$COLUMNS"
fi
else
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w "$COLUMNS"
echo "${response_data}"
fi
add_assistant_response_to_chat_message "$(escape "$response_data")"

Expand All @@ -439,15 +443,19 @@ while $running; do
handle_error "$response"
response_data=$(echo "$response" | jq -r '.choices[].text')

echo -e "$OVERWRITE_PROCESSING_LINE"
# if glow installed, print parsed markdown
if command -v glow &>/dev/null; then
echo -e "${CHATGPT_CYAN_LABEL}"
echo "${response_data}" | glow -
if [ -t 1 ]; then
echo -e "$OVERWRITE_PROCESSING_LINE"
# if glow installed, print parsed markdown
if command -v glow &>/dev/null; then
echo -e "${CHATGPT_CYAN_LABEL}"
echo "${response_data}" | glow -
else
# else remove empty lines and print
formatted_text=$(echo "${response_data}" | sed '1,2d; s/^A://g')
echo -e "${CHATGPT_CYAN_LABEL}${formatted_text}" | fold -s -w $COLUMNS
fi
else
# else remove empty lines and print
formatted_text=$(echo "${response_data}" | sed '1,2d; s/^A://g')
echo -e "${CHATGPT_CYAN_LABEL}${formatted_text}" | fold -s -w $COLUMNS
echo "${response_data}"
fi

if [ "$CONTEXT" = true ]; then
Expand Down