Allow input from redirected stdin

pull/42/head
Rafael Xavier de Souza 1 year ago
parent 192a67229a
commit 69f3799db0
  1. 13
      chatgpt.sh

@ -216,15 +216,16 @@ fi
running=true
# check input source
# if prompt already entered, run on pipe mode (run once, no chat)
# prompt from pipe
if [ -p /dev/stdin ]; then
pipe_mode_prompt+=$(cat -)
# prompt from argument
elif [ -n "$prompt" ]; then
if [ -n "$prompt" ]; then
pipe_mode_prompt=${prompt}
else
# 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)
# prompt from pipe
else
pipe_mode_prompt+=$(cat -)
fi
while $running; do

Loading…
Cancel
Save