From 16c02dc1f2c5a6258fd646d1f528862f90d9b18d Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:32:48 +0100 Subject: [PATCH] fix: Bugfixes --- README.md | 1 + zsh-copilot.plugin.zsh | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3a0dad0..51fcc4f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # zsh-copilot + Get suggestions **truly** in your shell. No `suggest` bullshit. Just press `CTRL + Z` and get your suggestion. https://github.com/Myzel394/zsh-copilot/assets/50424412/ed2bc8ac-ce49-4012-ab73-53cf6f3151a2 diff --git a/zsh-copilot.plugin.zsh b/zsh-copilot.plugin.zsh index 74495bf..88f5e97 100644 --- a/zsh-copilot.plugin.zsh +++ b/zsh-copilot.plugin.zsh @@ -4,8 +4,8 @@ (( ! ${+ZSH_COPILOT_SEND_CONTEXT} )) && typeset -g ZSH_COPILOT_SEND_CONTEXT=true -(( ! ${+ZSH_COPILOT_SEND_GIT_DIFF} )) && - typeset -g ZSH_COPILOT_SEND_GIT_DIFF=true +# (( ! ${+ZSH_COPILOT_SEND_GIT_DIFF} )) && +# typeset -g ZSH_COPILOT_SEND_GIT_DIFF=true (( ! ${+ZSH_COPILOT_DEBUG} )) && typeset -g ZSH_COPILOT_DEBUG=false @@ -25,17 +25,18 @@ function _suggest_ai() { zle -R "Thinking..." local PROMPT="$SYSTEM_PROMPT" - if [[ "$ZSH_COPILOT_SEND_GIT_DIFF" == 'true' ]]; then - if [[ $(git rev-parse --is-inside-work-tree) == 'true' ]]; then - local git_diff=$(git diff --staged --no-color) - local git_exit_code=$? - git_diff=$(echo "$git_diff" | tr -d '\n') - - if [[ git_exit_code -eq 0 ]]; then - PROMPT="$PROMPT; This is the git diff: <---->$git_diff<----> You may provide a git commit message if the user is trying to commit changes. You are an expert at committing changes, you don't give generic messages. You give the best commit messages" - fi - fi - fi + # Wasn't able to get this to work :( + # if [[ "$ZSH_COPILOT_SEND_GIT_DIFF" == 'true' ]]; then + # if [[ $(git rev-parse --is-inside-work-tree) == 'true' ]]; then + # local git_diff=$(git diff --staged --no-color) + # local git_exit_code=$? + # git_diff=$(echo "$git_diff" | tr '\\' ' ' | sed 's/[\$\"\`]/\\&/g' | tr '\\' '\\\\' | tr -d '\n') + # + # if [[ git_exit_code -eq 0 ]]; then + # PROMPT="$PROMPT; This is the git diff: <---->$git_diff<----> You may provide a git commit message if the user is trying to commit changes. You are an expert at committing changes, you don't give generic messages. You give the best commit messages" + # fi + # fi + # fi local data="{ \"model\": \"gpt-4\", @@ -46,9 +47,7 @@ function _suggest_ai() { }, { \"role\": \"user\", - \"content\": \"" - data+=$input - data+="\" + \"content\": \"$input\" } ] }" @@ -87,7 +86,7 @@ function zsh-copilot() { echo "Configurations:" echo " - ZSH_COPILOT_KEY: Key to press to get suggestions (default: ^z, value: $ZSH_COPILOT_KEY)." echo " - ZSH_COPILOT_SEND_CONTEXT: If \`true\`, zsh-copilot will send context information (whoami, shell, pwd, etc.) to the AI model (default: true, value: $ZSH_COPILOT_SEND_CONTEXT)." - echo " - ZSH_COPILOT_SEND_GIT_DIFF: If \`true\`, zsh-copilot will send the git diff (if available) to the AI model (default: true, value: $ZSH_COPILOT_SEND_GIT_DIFF)." + # echo " - ZSH_COPILOT_SEND_GIT_DIFF: If \`true\`, zsh-copilot will send the git diff (if available) to the AI model (default: true, value: $ZSH_COPILOT_SEND_GIT_DIFF)." } zle -N _suggest_ai