0xacx / chatGPT-shell-cli

Simple shell script to use OpenAI's ChatGPT and DALL-E from the terminal. No Python or JS required.
https://gptshell.cc
MIT License
1.05k stars 150 forks source link

Some suggestions #55

Open Generator opened 1 year ago

Generator commented 1 year ago

1. Don't mess with profiles

Changing user/system profiles not a good idea and can create a mess, use own config instead

Example install.sh:

if [[ $EUID -eq 0 ]]; then
    mkdir -p /etc/chatgpt/chatgpt.txt
    echo "OPENAI_KEY=$key" > /etc/chatgpt/chatgpt.conf
else
    mkdir -p "$HOME/.config/chatgpt/chatgpt.conf"
    echo "OPENAI_KEY=$key" > "$HOME/.config/chatgpt/chatgpt.conf"
fi

Example chatgpt.sh:

if [[ -f "$HOME/.config/chatgpt/chatgpt.conf" ]]; then
    . "$HOME/.config/chatgpt/chatgpt.conf"
elif [[ -f "/etc/chatgpt/chatgpt.conf" ]]; then
  . "/etc/chatgpt/chatgpt.conf"
fi

# If OPENAI_KEY empty warn user
if [ -z $OPENAI_KEY ]; then
    echo "OPENAI_KEY not set, please add to your env or config file"
fi

2. Allow user to install on $HOME

if [[ $EUID -eq 0 ]]; then
   CHATGPT_BIN="/usr/local/bin/"
else
   CHATGPT_BIN="$HOME/local/bin"
   # Warn user about PATH
   echo 'Add $HOME/local/bin to your PATH environment'
   echo 'Example: PATH=$PATH:$HOME/local/bin'  # Don't use double-quote to not expand $PATH
fi

# Create path of not exist
mkdir -p "$CHATGPT_BIN"

# Then install to CHATGPT_BIN
curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/chatgpt.sh -o "$CHATGPT_BIN/chatgpt"

# Same with imgcat
curl -sS https://iterm2.com/utilities/imgcat -o "$CHATGPT_BIN/imgcat"
Zeioth commented 1 year ago
  1. Was already reported and should have been fixed yesterday. Try to reinstall (or use chatgpt-shell-cli-git if you are on arch).
  2. ~/.local/bin is reserved for executables created by you, the user. All packages, are always installed on /usr/bin, unless they are not managed by the package manager, in which case they go to /usr/local/bin

For more info about 2, you can check the arch wiki.

0xacx commented 1 year ago

@Generator @Zeioth Firstly, thank you very for taking the interest and time to suggest changes! 👍 I think that adding the key on a .conf file during install is a great idea and improves the security of the key. Please consider submitting a PR with the changes! I'd be very happy to review and merge that.

The convention for mac is to install scripts in /usr/local/bin and that's why the script installs it there.

About editing profile files, adding the script to $PATH is essential for providing a good user experience. The install script is meant for users who don't know, or don't care where the script is installed and what their $PATH is. I think that not providing that, would deter first-time users from using it. I believe that users who care where the script is installed, are able (and probably prefer) to install it manually since it is a single file (two with imgcat) and not a difficult process to copy a file and add it to $PATH. In my mind, the install script is not meant to be a script with exhaustive level of control and countless options, but rather a quick way to get started in seconds.

In my opinion, for specific environments i.e. Arch Linux, I think the right place to handle the different conventions are the specific install scripts, like the PKGBUILD file. Lmk what you think.

Zeioth commented 1 year ago

Ok I agree with all. I have this couple TODOS for the future then: