Skip to content

Instantly share code, notes, and snippets.

@hookdump
Created April 18, 2023 20:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hookdump/46cd8bc5eba77552657b634983080c5a to your computer and use it in GitHub Desktop.
Save hookdump/46cd8bc5eba77552657b634983080c5a to your computer and use it in GitHub Desktop.
Ask ChatGPT in ZSH
# Paste your OpenAI API Key here
export OPENAI_API_KEY="sk-..."
# Display colors
RED='\033[0;31m'
NC='\033[0m' # No Color
# GPT function
function gpt {
set +o nomatch # disable nomatch option
nvm use gpt --silent # node should be >= 18.13.0, you can use an alias for that version
local input="$*" # concat args into single string
echo -e "${RED}Prompt:${NC} $input"
echo -e "${RED}ChatGPT:${NC}"
chatgpt "$input" # call chatgpt cli
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment