Skip to content

Fix #127, support Ctrl-C/Ctrl-D #128

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

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
18 changes: 17 additions & 1 deletion chatgpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ else
pipe_mode_prompt+=$(cat -)
fi

function handle_ctrl_c {
# newline
echo ""
}
trap handle_ctrl_c INT

while $running; do

if [ -z "$pipe_mode_prompt" ]; then
Expand All @@ -326,7 +332,17 @@ while $running; do
prompt=$(escape "$input_from_temp_file")
else
echo -e "\nEnter a prompt:"
read -e prompt
while true; do
prompt=$(read -e prompt && echo $prompt || exit 1)
# Ctrl-D
if [[ $? == 1 ]]; then
exit
fi
# Ctrl-C
if [ -n "$prompt" ]; then
break
fi
done
fi
if [[ ! $prompt =~ ^(exit|q)$ ]]; then
echo -ne $PROCESSING_LABEL
Expand Down