This script allows you to interact with OpenAI's GPT model directly from your zsh terminal. It's a quick way to get help on command syntax or any query without leaving the terminal. The script has no memory so each interaction is independent.
- Copy this script to a directory in your
$PATH
. For example,cp chat.sh /usr/local/bin/
. - Make it executable:
chmod +x /usr/local/bin/chat.sh
. - Create an alias in your bash config such as
~/.zshrc
:alias chat=/usr/local/bin/chat.sh
. - Add your OpenAI API key as an environment variable. For example, add
export OPENAI_API_KEY=<your-api-key>
in~/.zshrc
. API Key Instructions - Install jq for JSON parsing:
brew install jq
. Install instructions
You can prompt the script in two ways:
chat "Your query here."
- Pros: Quick for simple queries. Allows command chaining with pipes
|
. - Cons: Cannot include the same type of quotes both inside and outside the query. Use a combination of double and single quotes if necessary.
chat
Your query here.
Add as many lines as needed.
END
- Pros: Supports long queries and line breaks. Allows quotes inside the prompt.
- Cons: Requires manual typing of
END
to finish input.
- For a quick query:
- For a multiline query:
- 8-bit ANSI text decorations are used to decorate the response. 16-bit colors may not work in all environments. Tweak the prompt to change color decorations. It's finicky.
- Customize the system message as needed.
- TODO: Include support for light mode. (eww.) This version only works with dark themes.