Created pip package

This commit is contained in:
Victor Mylle 2022-12-01 18:31:36 +01:00
parent 2dd68657f7
commit 09f9129e58
5 changed files with 38 additions and 50 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
demos/
.DS_Store
build/
CopilotTerminal.egg-info

View File

@ -4,6 +4,8 @@ import os
import sys
import time
from os.path import expanduser
import click
# get a new github copilot token
def get_token():
@ -105,14 +107,14 @@ def get_suggestion(prompt, token):
return "Command not found"
# cursor_position_char = int(sys.argv[1])
@click.group()
def main():
pass
# Read the input prompt from stdin.
# buffer = sys.stdin.read()
buffer = 'change python version to 3.10'
# ---
prompt_prefix = "!/bin/bash\n\n" + buffer + ":\n"
token = get_token()
print(get_suggestion(prompt_prefix, token))
@main.command()
@click.argument('prompt', nargs=-1)
def generate_suggestion(prompt):
prompt = " ".join(prompt)
prompt = "!/bin/bash\n\n" + prompt + ":\n"
token = get_token()
print(get_suggestion(prompt, token))

22
setup.py Normal file
View File

@ -0,0 +1,22 @@
from setuptools import setup
from setuptools.command.install import install
import os
setup(
name='CopilotTerminal',
version='0.1.0',
description='zsh plugin to use copilot command predictions in the terminal',
author='Victor Mylle',
author_email='victor.mylle@hotmail.com',
license='MIT',
py_modules=['copilot'],
install_requires=[
'requests',
'click',
],
entry_points='''
[console_scripts]
ct=copilot:generate_suggestion
''',
)

View File

@ -1 +1 @@
{"expires_at": 1669911119, "public_suggestions": "disabled", "refresh_in": 1500, "sku": "free_educational", "telemetry": "disabled", "token": "tid=d47460691ef58366f713e508d59d807b;exp=1669911119;sku=free_educational:ecb129f512a32bd216e89485725dc7a8edae9d8930ab38c05c0e14022af4903e", "tracking_id": "d47460691ef58366f713e508d59d807b"}
{"expires_at": 1669917293, "public_suggestions": "disabled", "refresh_in": 1500, "sku": "free_educational", "telemetry": "disabled", "token": "tid=d47460691ef58366f713e508d59d807b;exp=1669917293;sku=free_educational:f9553e702e2a159aa3459e09a3b0b2c0ca83a11c4042ea928c8af5cf8732063b", "tracking_id": "d47460691ef58366f713e508d59d807b"}

View File

@ -1,38 +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}
#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