Skip to content

Commit 586e5ac

Browse files
authored
Merge branch 'add-help-command' into main
2 parents 5b7787e + e777711 commit 586e5ac

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

chatgpt.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ COMMAND_GENERATION_PROMPT="Return a one-line bash command with the functionality
1515

1616
CHATGPT_CYAN_LABEL="\n\033[36mchatgpt \033[0m"
1717

18+
PROCESSING_LABEL="\033[90mprocessing... \033[0m"
19+
1820
usage() {
1921
cat << EOF
2022
A simple, lightweight shell script to use OpenAI's chatGPT and DALL-E from the terminal without installing python or node.js.
@@ -272,6 +274,9 @@ while $running; do
272274
if [ -z "$pipe_mode_prompt" ]; then
273275
echo -e "\nEnter a prompt:"
274276
read -e prompt
277+
if [ "$prompt" != "exit" ] && [ "$prompt" != "q" ]; then
278+
echo -e $PROCESSING_LABEL
279+
fi
275280
else
276281
# set vars for pipe mode
277282
prompt=${pipe_mode_prompt}
@@ -328,7 +333,7 @@ while $running; do
328333
response_data=$(echo $response | jq -r '.choices[].message.content')
329334

330335
if [[ "$prompt" =~ ^command: ]]; then
331-
echo -e "${CHATGPT_CYAN_LABEL} ${response_data}\n"
336+
echo -e "${CHATGPT_CYAN_LABEL} ${response_data}" | fold -s -w $COLUMNS
332337
dangerous_commands=("rm" ">" "mv" "mkfs" ":(){:|:&};" "dd" "chmod" "wget" "curl")
333338

334339
for dangerous_command in "${dangerous_commands[@]}"; do
@@ -360,7 +365,7 @@ while $running; do
360365
handle_error "$response"
361366
response_data=$(echo "$response" | jq -r '.choices[].message.content')
362367

363-
echo -e "${CHATGPT_CYAN_LABEL}${response_data}"
368+
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w $COLUMNS
364369

365370
escaped_response_data=$(echo "$response_data" | sed 's/"/\\"/g')
366371
add_assistant_response_to_chat_message "$chat_message" "$escaped_response_data"
@@ -380,7 +385,7 @@ while $running; do
380385
request_to_completions "$request_prompt"
381386
handle_error "$response"
382387
response_data=$(echo "$response" | jq -r '.choices[].text' | sed '1,2d; s/^A://g')
383-
echo -e "${CHATGPT_CYAN_LABEL}${response_data}"
388+
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w $COLUMNS
384389

385390
if [ "$CONTEXT" = true ]; then
386391
escaped_response_data=$(echo "$response_data" | sed 's/"/\\"/g')

install.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,25 @@ if [ "$answer" == "Yes" ] || [ "$answer" == "yes" ] || [ "$answer" == "y" ] || [
4848
# zsh profile
4949
if [ -f ~/.zprofile ]; then
5050
echo "export OPENAI_KEY=$key" >>~/.zprofile
51-
echo 'export PATH=$PATH:/usr/local/bin' >>~/.zprofile
51+
if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
52+
echo 'export PATH=$PATH:/usr/local/bin' >>~/.zprofile
53+
fi
5254
echo "OpenAI key and chatgpt path added to ~/.zprofile"
5355
source ~/.zprofile
5456
# bash profile mac
5557
elif [ -f ~/.bash_profile ]; then
5658
echo "export OPENAI_KEY=$key" >>~/.bash_profile
57-
echo 'export PATH=$PATH:/usr/local/bin' >>~/.bash_profile
59+
if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
60+
echo 'export PATH=$PATH:/usr/local/bin' >>~/.bash_profile
61+
fi
5862
echo "OpenAI key and chatgpt path added to ~/.bash_profile"
5963
source ~/.bash_profile
6064
# profile ubuntu
6165
elif [ -f ~/.profile ]; then
6266
echo "export OPENAI_KEY=$key" >>~/.profile
63-
echo 'export PATH=$PATH:/usr/local/bin' >>~/.profile
67+
if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
68+
echo 'export PATH=$PATH:/usr/local/bin' >>~/.profile
69+
fi
6470
echo "OpenAI key and chatgpt path added to ~/.profile"
6571
source ~/.profile
6672
else

0 commit comments

Comments
 (0)