Added option to copy command to clipboard

This commit is contained in:
2022-12-02 14:04:44 +01:00
parent 3fc206b0c6
commit 3dc0b8f1d2
2 changed files with 11 additions and 6 deletions

View File

@@ -8,10 +8,7 @@ import click
from rich import print
from rich.panel import Panel
from rich.text import Text
import signal
import subprocess
from threading import Thread
from pynput.keyboard import Key, Controller
import pyperclip
try:
import gnureadline as readline
except ImportError:
@@ -131,7 +128,7 @@ def generate_suggestion(prompt):
token = get_token()
suggestion = get_suggestion(prompt, token)
panel = Panel(Text(suggestion, justify="center"), title_align="center", title="Accept? \[y/n/e]", expand=False)
panel = Panel(Text(suggestion, justify="center"), title_align="center", title="Execute? \[y/n/e/c]", expand=False)
print(panel)
# read a character from stdin without displaying it
c = click.getchar()
@@ -153,4 +150,12 @@ def generate_suggestion(prompt):
# remove pre input hook
readline.set_pre_input_hook()
# set history
readline.clear_history()
readline.add_history(line)
elif c == "c":
# copy the suggestion to clipboard
pyperclip.copy(suggestion)
print("Copied to clipboard")

View File

@@ -1 +1 @@
{"expires_at": 1669980922, "public_suggestions": "disabled", "refresh_in": 1500, "sku": "free_educational", "telemetry": "disabled", "token": "tid=d47460691ef58366f713e508d59d807b;exp=1669980922;sku=free_educational:fb44337ee996917b43d51aa8bd1553ecce5ef1d7880333106ee25689648ca133", "tracking_id": "d47460691ef58366f713e508d59d807b"}
{"expires_at": 1669988057, "public_suggestions": "disabled", "refresh_in": 1500, "sku": "free_educational", "telemetry": "disabled", "token": "tid=d47460691ef58366f713e508d59d807b;exp=1669988057;sku=free_educational:8f88da8df463706243fcf52df0f6e9d5ec3ca0126ccdc919c2528ce4f7573101", "tracking_id": "d47460691ef58366f713e508d59d807b"}