From 5e263aa9b44a74cc250221ef6b70d66f26a9cae0 Mon Sep 17 00:00:00 2001 From: Anders Steen Date: Tue, 25 Jul 2023 14:17:26 +0200 Subject: [PATCH 1/3] Auto install zshgpt with pipx or pip if not installed --- zsh_plugin.zsh | 20 ++++++++++++++++++++ zshgpt.plugin.zsh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 zsh_plugin.zsh create mode 100644 zshgpt.plugin.zsh diff --git a/zsh_plugin.zsh b/zsh_plugin.zsh new file mode 100644 index 0000000..343fe64 --- /dev/null +++ b/zsh_plugin.zsh @@ -0,0 +1,20 @@ +#!/bin/zsh + +# This ZSH plugin reads the text from the current buffer +# and uses a Python script to complete the text. + +create_completion() { + # Get the text typed until now. + text=${BUFFER} + completion=$(zshgpt $text ) + # Add completion to the current buffer. + BUFFER="${text}"$'\n'"${completion}" + # Put the cursor at the end of the line. + CURSOR=${#BUFFER} +} + +# Bind the create_completion function to a key. +zle -N create_completion + +setopt interactivecomments +bindkey '^G' create_completion diff --git a/zshgpt.plugin.zsh b/zshgpt.plugin.zsh new file mode 100644 index 0000000..c8988cd --- /dev/null +++ b/zshgpt.plugin.zsh @@ -0,0 +1,31 @@ +#!/bin/zsh + +# This ZSH plugin reads the text from the current buffer +# and uses a Python script to complete the text. + +# If zshgpt is not installed... +if (( $+commands[zshgpt] )) then + echo "zshgpt already installed" + # ...try to install with pipx... +elif (( $+commands[pipx] )) then + pipx install zshgpt +else + # ... or normal pip. + python -m pip install zshgpt +fi + +create_completion() { + # Get the text typed until now. + text=${BUFFER} + completion=$(zshgpt $text ) + # Add completion to the current buffer. + BUFFER="${text}"$'\n'"${completion}" + # Put the cursor at the end of the line. + CURSOR=${#BUFFER} +} + +# Bind the create_completion function to a key. +zle -N create_completion + +setopt interactivecomments +bindkey '^G' create_completion From a91888e913210cbc91c70d7154fe3282bd739af4 Mon Sep 17 00:00:00 2001 From: Anders Steen Date: Tue, 25 Jul 2023 15:06:34 +0200 Subject: [PATCH 2/3] Deleted old plugin files --- zsh_plugin.zsh | 20 -------------------- zsh_plugin/zsh_plugin.zsh | 20 -------------------- 2 files changed, 40 deletions(-) delete mode 100644 zsh_plugin.zsh delete mode 100644 zsh_plugin/zsh_plugin.zsh diff --git a/zsh_plugin.zsh b/zsh_plugin.zsh deleted file mode 100644 index 343fe64..0000000 --- a/zsh_plugin.zsh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/zsh - -# This ZSH plugin reads the text from the current buffer -# and uses a Python script to complete the text. - -create_completion() { - # Get the text typed until now. - text=${BUFFER} - completion=$(zshgpt $text ) - # Add completion to the current buffer. - BUFFER="${text}"$'\n'"${completion}" - # Put the cursor at the end of the line. - CURSOR=${#BUFFER} -} - -# Bind the create_completion function to a key. -zle -N create_completion - -setopt interactivecomments -bindkey '^G' create_completion diff --git a/zsh_plugin/zsh_plugin.zsh b/zsh_plugin/zsh_plugin.zsh deleted file mode 100644 index 343fe64..0000000 --- a/zsh_plugin/zsh_plugin.zsh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/zsh - -# This ZSH plugin reads the text from the current buffer -# and uses a Python script to complete the text. - -create_completion() { - # Get the text typed until now. - text=${BUFFER} - completion=$(zshgpt $text ) - # Add completion to the current buffer. - BUFFER="${text}"$'\n'"${completion}" - # Put the cursor at the end of the line. - CURSOR=${#BUFFER} -} - -# Bind the create_completion function to a key. -zle -N create_completion - -setopt interactivecomments -bindkey '^G' create_completion From 920e1935fda99ff1fa243e457d1eda9fb9c6879e Mon Sep 17 00:00:00 2001 From: Anders Steen Date: Tue, 25 Jul 2023 15:07:00 +0200 Subject: [PATCH 3/3] Updated README --- README.md | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 137b1d4..d7b894b 100644 --- a/README.md +++ b/README.md @@ -37,17 +37,38 @@ If asked a question that will not resolve in a command, GPT is instructed to use ``` ## Prerequisite +### Must have * Python >= 3.7 * ZSH + Oh-my-zsh * Valid Openai API-key * make sure to save under `OPENAI_API_KEY` env. - * `export OPENAI_API_KEY='sk-...'` + * **`export OPENAI_API_KEY='sk-...'`** + +### Nice to have +* pipx +* Oh-my-zsh +* zplug ## Installation +⚠️All installations needs to have OPEN_API_KEY set⚠️. -With zshgpt alone, you can ask questions with `zshgpt # Show me all my drives` and it will return an answer from GPT. But the true performance boost comes when you also add the zsh plugin. -```bash -pip install zshgpt # Or preferably install with pipx +`~/.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 +```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 +```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 ``` @@ -61,6 +82,18 @@ plugins( ) ``` +```zsh +omz reload +``` + +### With zplug +`~/.zshrc` +``` +... +zplug "AndersSteenNilsen/zshgpt" +zplug load +``` + ## Future plans ### Functionaliy