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")