Initial Commit
This commit is contained in:
38
zsh_copilot.plugin.zsh
Executable file
38
zsh_copilot.plugin.zsh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user