Skip to content

Commit bfb3c7d

Browse files
committed
Fix 0xacx#127, support Ctrl-C/Ctrl-D
1 parent eec4d6d commit bfb3c7d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

chatgpt.sh

+17-1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ else
320320
pipe_mode_prompt+=$(cat -)
321321
fi
322322

323+
function handle_ctrl_c {
324+
# newline
325+
echo ""
326+
}
327+
trap handle_ctrl_c INT
328+
323329
while $running; do
324330

325331
if [ -z "$pipe_mode_prompt" ]; then
@@ -330,7 +336,17 @@ while $running; do
330336
prompt=$(escape "$input_from_temp_file")
331337
else
332338
echo -e "\nEnter a prompt:"
333-
read -e prompt
339+
while true; do
340+
prompt=$(read -e prompt && echo $prompt || exit 1)
341+
# Ctrl-D
342+
if [[ $? == 1 ]]; then
343+
exit
344+
fi
345+
# Ctrl-C
346+
if [ -n "$prompt" ]; then
347+
break
348+
fi
349+
done
334350
fi
335351
if [[ ! $prompt =~ ^(exit|q)$ ]]; then
336352
echo -ne $PROCESSING_LABEL

0 commit comments

Comments
 (0)