Skip to content

Commit 69f3799

Browse files
committed
Allow input from redirected stdin
1 parent 192a672 commit 69f3799

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

chatgpt.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,16 @@ fi
216216

217217
running=true
218218
# check input source
219-
# if prompt already entered, run on pipe mode (run once, no chat)
220-
# prompt from pipe
221-
if [ -p /dev/stdin ]; then
222-
pipe_mode_prompt+=$(cat -)
223219
# prompt from argument
224-
elif [ -n "$prompt" ]; then
220+
if [ -n "$prompt" ]; then
225221
pipe_mode_prompt=${prompt}
226-
else
222+
# if input file_descriptor is a terminal
223+
elif [ -t 0 ]; then
227224
echo -e "Welcome to chatgpt. You can quit with '\033[36mexit\033[0m'."
225+
# if prompt already entered, run on pipe mode (run once, no chat)
226+
# prompt from pipe
227+
else
228+
pipe_mode_prompt+=$(cat -)
228229
fi
229230

230231
while $running; do

0 commit comments

Comments
 (0)