From 09f9129e58a55be853ebc3951713531166aa55bb Mon Sep 17 00:00:00 2001 From: Victor Mylle Date: Thu, 1 Dec 2022 18:31:36 +0100 Subject: [PATCH] Created pip package --- .gitignore | 4 +++- copilot.py | 22 ++++++++++++---------- setup.py | 22 ++++++++++++++++++++++ token.json | 2 +- zsh_copilot.plugin.zsh | 38 -------------------------------------- 5 files changed, 38 insertions(+), 50 deletions(-) create mode 100644 setup.py delete mode 100755 zsh_copilot.plugin.zsh diff --git a/.gitignore b/.gitignore index a510eca..adac33f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ demos/ -.DS_Store \ No newline at end of file +.DS_Store +build/ +CopilotTerminal.egg-info \ No newline at end of file diff --git a/copilot.py b/copilot.py index a03e652..e0e59a3 100755 --- a/copilot.py +++ b/copilot.py @@ -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)) \ No newline at end of file +@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)) \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5cc6eb6 --- /dev/null +++ b/setup.py @@ -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 + ''', + +) \ No newline at end of file diff --git a/token.json b/token.json index 90679de..bc94338 100644 --- a/token.json +++ b/token.json @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/zsh_copilot.plugin.zsh b/zsh_copilot.plugin.zsh deleted file mode 100755 index d3e482a..0000000 --- a/zsh_copilot.plugin.zsh +++ /dev/null @@ -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 \ No newline at end of file