mirror of
https://github.com/0xacx/chatGPT-shell-cli.git
synced 2025-02-22 18:55:29 +00:00
Merge pull request #42 from rxaviers/feat-read-from-stdin
Allow input from redirected stdin
This commit is contained in:
commit
d79cf405ad
13
chatgpt.sh
13
chatgpt.sh
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user