fix: Bugfixes

This commit is contained in:
Myzel394 2024-03-24 12:32:48 +01:00
parent 362073c318
commit 16c02dc1f2
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 17 additions and 17 deletions

View File

@ -1,5 +1,6 @@
# zsh-copilot # zsh-copilot
Get suggestions **truly** in your shell. No `suggest` bullshit. Just press `CTRL + Z` and get your suggestion. 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 https://github.com/Myzel394/zsh-copilot/assets/50424412/ed2bc8ac-ce49-4012-ab73-53cf6f3151a2

View File

@ -4,8 +4,8 @@
(( ! ${+ZSH_COPILOT_SEND_CONTEXT} )) && (( ! ${+ZSH_COPILOT_SEND_CONTEXT} )) &&
typeset -g ZSH_COPILOT_SEND_CONTEXT=true typeset -g ZSH_COPILOT_SEND_CONTEXT=true
(( ! ${+ZSH_COPILOT_SEND_GIT_DIFF} )) && # (( ! ${+ZSH_COPILOT_SEND_GIT_DIFF} )) &&
typeset -g ZSH_COPILOT_SEND_GIT_DIFF=true # typeset -g ZSH_COPILOT_SEND_GIT_DIFF=true
(( ! ${+ZSH_COPILOT_DEBUG} )) && (( ! ${+ZSH_COPILOT_DEBUG} )) &&
typeset -g ZSH_COPILOT_DEBUG=false typeset -g ZSH_COPILOT_DEBUG=false
@ -25,17 +25,18 @@ function _suggest_ai() {
zle -R "Thinking..." zle -R "Thinking..."
local PROMPT="$SYSTEM_PROMPT" local PROMPT="$SYSTEM_PROMPT"
if [[ "$ZSH_COPILOT_SEND_GIT_DIFF" == 'true' ]]; then # Wasn't able to get this to work :(
if [[ $(git rev-parse --is-inside-work-tree) == 'true' ]]; then # if [[ "$ZSH_COPILOT_SEND_GIT_DIFF" == 'true' ]]; then
local git_diff=$(git diff --staged --no-color) # if [[ $(git rev-parse --is-inside-work-tree) == 'true' ]]; then
local git_exit_code=$? # local git_diff=$(git diff --staged --no-color)
git_diff=$(echo "$git_diff" | tr -d '\n') # 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" # if [[ git_exit_code -eq 0 ]]; then
fi # 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 # fi
# fi
local data="{ local data="{
\"model\": \"gpt-4\", \"model\": \"gpt-4\",
@ -46,9 +47,7 @@ function _suggest_ai() {
}, },
{ {
\"role\": \"user\", \"role\": \"user\",
\"content\": \"" \"content\": \"$input\"
data+=$input
data+="\"
} }
] ]
}" }"
@ -87,7 +86,7 @@ function zsh-copilot() {
echo "Configurations:" echo "Configurations:"
echo " - ZSH_COPILOT_KEY: Key to press to get suggestions (default: ^z, value: $ZSH_COPILOT_KEY)." 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_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 zle -N _suggest_ai