CopilotTerminal/zsh_copilot.plugin.zsh
2022-12-01 16:45:04 +01:00

38 lines
916 B
Bash
Executable File

#!/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}
#echo $cursor_line $cursor_col
completion=$(echo -n "$text" | python3 /Users/victormylle/Nextcloud/Documents/Projects/CopilotTerminal/copilot.py $CURSOR)
# new line
echo ""
# print completion without formatting
print -Pn -- "%F{green}$completion%f\n"
print -Pn -- "Accept command (%F{green}y%f,%F{red}n%f,e)"
read -sk
if [[ $REPLY =~ ^[Yy]$ ]]; then
BUFFER=$completion
zle accept-line
elif [[ $REPLY =~ ^[Ee]$ ]]; then
BUFFER=$completion
# set cursor to end of line
zle redisplay
zle end-of-line
else
zle redisplay
fi
}
# Bind the create_completion function to a key.
zle -N create_completion