Merge pull request #42 from rxaviers/feat-read-from-stdin

Allow input from redirected stdin
This commit is contained in:
0xacx 2023-03-17 14:58:14 +02:00 committed by GitHub
commit d79cf405ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -216,15 +216,16 @@ fi
running=true running=true
# check input source # check input source
# prompt from argument
if [ -n "$prompt" ]; then
pipe_mode_prompt=${prompt}
# if input file_descriptor is a terminal
elif [ -t 0 ]; then
echo -e "Welcome to chatgpt. You can quit with '\033[36mexit\033[0m'."
# if prompt already entered, run on pipe mode (run once, no chat) # if prompt already entered, run on pipe mode (run once, no chat)
# prompt from pipe # prompt from pipe
if [ -p /dev/stdin ]; then
pipe_mode_prompt+=$(cat -)
# prompt from argument
elif [ -n "$prompt" ]; then
pipe_mode_prompt=${prompt}
else else
echo -e "Welcome to chatgpt. You can quit with '\033[36mexit\033[0m'." pipe_mode_prompt+=$(cat -)
fi fi
while $running; do while $running; do