From 439a3e848e500d7f3feac990ad2145d60c290d59 Mon Sep 17 00:00:00 2001 From: DREVET Olivier Date: Thu, 17 Jul 2025 03:56:52 +0200 Subject: [PATCH] Implement modify option for generated shell command (#566) Co-authored-by: Farkhod Sadykov --- pyproject.toml | 1 + sgpt/app.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fca02fd..6e33435 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ dependencies = [ "distro >= 1.8.0, < 2.0.0", "instructor >= 1.0.0, < 2.0.0", 'pyreadline3 >= 3.4.1, < 4.0.0; sys_platform == "win32"', + "prompt_toolkit >= 3.0.51", ] [project.optional-dependencies] diff --git a/sgpt/app.py b/sgpt/app.py index 9c711e6..e72f8ba 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -7,6 +7,7 @@ import sys import typer from click import BadArgumentUsage from click.types import Choice +from prompt_toolkit import PromptSession from sgpt.config import cfg from sgpt.function import get_openai_schemas @@ -237,10 +238,12 @@ def main( functions=function_schemas, ) + session = PromptSession() + while shell and interaction: option = typer.prompt( - text="[E]xecute, [D]escribe, [A]bort", - type=Choice(("e", "d", "a", "y"), case_sensitive=False), + text="[E]xecute, [M]odify, [D]escribe, [A]bort", + type=Choice(("e", "m", "d", "a", "y"), case_sensitive=False), default="e" if cfg.get("DEFAULT_EXECUTE_SHELL_CMD") == "true" else "a", show_choices=False, show_default=False, @@ -248,6 +251,9 @@ def main( if option in ("e", "y"): # "y" option is for keeping compatibility with old version. run_command(full_completion) + elif option == "m": + full_completion = session.prompt('', default=full_completion) + continue elif option == "d": DefaultHandler(DefaultRoles.DESCRIBE_SHELL.get_role(), md).handle( full_completion,