@@ -10,7 +10,7 @@ COMMAND_GENERATION_PROMPT="Return a one-line bash command with the functionality
10
10
11
11
CHATGPT_CYAN_LABEL=" \n\033[36mchatgpt \033[0m"
12
12
13
- PROCESSING_LABEL=" \n\033[90mprocessing ... \033[0m"
13
+ PROCESSING_LABEL=" \n\033[90mProcessing ... \033[0m"
14
14
15
15
if [[ -z " $OPENAI_KEY " ]]; then
16
16
echo " You need to set your OPENAI_KEY to use this script"
@@ -375,8 +375,14 @@ while $running; do
375
375
handle_error " $response "
376
376
response_data=$( echo " $response " | jq -r ' .choices[].message.content' )
377
377
378
- echo -e " ${CHATGPT_CYAN_LABEL}${response_data} " | fold -s -w $COLUMNS
379
-
378
+ # if glow installed, print parsed markdown
379
+ if command -v glow & > /dev/null; then
380
+ formatted_text=$( echo " ${response_data} " | glow)
381
+ echo -e " ${CHATGPT_CYAN_LABEL} "
382
+ echo -e " ${formatted_text} "
383
+ else
384
+ echo -e " ${CHATGPT_CYAN_LABEL}${response_data} " | fold -s -w $COLUMNS
385
+ fi
380
386
escaped_response_data=$( echo " $response_data " | sed ' s/"/\\"/g' )
381
387
add_assistant_response_to_chat_message " $chat_message " " $escaped_response_data "
382
388
@@ -394,8 +400,18 @@ while $running; do
394
400
395
401
request_to_completions " $request_prompt "
396
402
handle_error " $response "
397
- response_data=$( echo " $response " | jq -r ' .choices[].text' | sed ' 1,2d; s/^A://g' )
398
- echo -e " ${CHATGPT_CYAN_LABEL}${response_data} " | fold -s -w $COLUMNS
403
+ response_data=$( echo " $response " | jq -r ' .choices[].text' )
404
+
405
+ # if glow installed, print parsed markdown
406
+ if command -v glow & > /dev/null; then
407
+ formatted_text=$( echo " ${response_data} " | glow)
408
+ echo -e " ${CHATGPT_CYAN_LABEL} "
409
+ echo -e " ${formatted_text} "
410
+ else
411
+ # else remove empty lines and print
412
+ formatted_text=$( echo " ${response_data} " | sed ' 1,2d; s/^A://g' )
413
+ echo -e " ${CHATGPT_CYAN_LABEL}${formatted_text} " | fold -s -w $COLUMNS
414
+ fi
399
415
400
416
if [ " $CONTEXT " = true ]; then
401
417
escaped_response_data=$( echo " $response_data " | sed ' s/"/\\"/g' )
0 commit comments