Skip to main content

Level up z shell with GPT

Project description

zshgpt

PyPI - Version PyPI - Python Version

Icon

Table of Contents

About

Gif of usage

Heavily inspired by the abandoned project https://github.com/microsoft/Codex-CLI Made into a oh-my-zsh plugin.

In your zsh console, type a question, starting with comment sign #, hit ctrl+g and get an answer.

# Who edited README.MD last according to git history?

ChatGPT will then answer with e.g.:

git log -1 --format="%an" README.md

Hit enter to execute or ctrl+c to deny.

If asked a question that will not resolve in a command, GPT is instructed to use #.

# Who was Norways first prime minister?
# Norway's first prime minister was Frederik Stang, serving from 1873 to 1880.

Prerequisite

Must have

  • Python >= 3.8
  • ZSH + Oh-my-zsh
  • Valid Openai API-key
    • make sure to save under OPENAI_API_KEY env.
    • export OPENAI_API_KEY='sk-...'

Nice to have

  • pipx
  • Oh-my-zsh
  • zplug

Installation

⚠️All installations needs to have OPEN_API_KEY set⚠️.

~/.zshrc

export OPEN_API_KEY="sk-..."

Standalone python package

With zshgpt alone pipx install zshgpt , you can ask questions with zshgpt # Show me all my drives and it will return an answer from GPT. But the true ✨magic✨ comes when you also add the zsh plugin.

Manually with zsh

curl https://raw.githubusercontent.com/AndersSteenNilsen/zshgpt/main/zshgpt.plugin.zsh -o ~ # Copy plugin
echo "source ~/zshgpt.plugin.zsh" >> ~/.zshrc # Add to zshrc
exec zsh # Reload zsh

Manually with oh-my-zsh

mkdir $ZSH_CUSTOM/plugins/zshgpt
curl https://raw.githubusercontent.com/AndersSteenNilsen/zshgpt/main/zsh_plugin/zsh_plugin.zsh -o $ZSH_CUSTOM/plugins/zshgpt/zshgpt.plugin.zsh

Then add zshgpt in your list of plugins in ~/.zshrc

plugins(
    ...
    zshgpt
    ...
)
omz reload

With zplug

~/.zshrc

...
zplug "AndersSteenNilsen/zshgpt"
zplug load

Future plans

Functionaliy

  • Remember last couple messages so you could do something like:
# Open README.md <-- USER
# You can open the README.md file using a text editor of your choice. Here's an example using vim:

vim README.md
# But I don't have vim, can you open it in VSCode? <-- USER
code README.md
  • Cycle through choices
  • Give possibility to switch model
  • Give info about how many token has been used

CI/CD

  • Pre-commit.
  • Add to flatpack or similar to ease installation.
  • Publish as part of git flow.

License

zshgpt is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zshgpt-0.5.0.tar.gz (153.3 kB view hashes)

Uploaded Source

Built Distribution

zshgpt-0.5.0-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page