From bd81f8be940cbdb07443e314dfba7a5d910a44c9 Mon Sep 17 00:00:00 2001 From: Eaad Date: Mon, 23 Sep 2024 16:50:47 +0300 Subject: [PATCH 1/3] Add modify option to prompt and update get_edited_prompt function to accept initial prompt text --- sgpt/app.py | 7 +++++-- sgpt/utils.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sgpt/app.py b/sgpt/app.py index 733b7ce4..fa78fb77 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -237,8 +237,8 @@ def main( 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, [D]escribe, [A]bort [M]odify", + type=Choice(("e", "d", "a", "y", "m"), case_sensitive=False), default="e" if cfg.get("DEFAULT_EXECUTE_SHELL_CMD") == "true" else "a", show_choices=False, show_default=False, @@ -256,6 +256,9 @@ def main( functions=function_schemas, ) continue + elif option == "m": + prompt = get_edited_prompt(full_completion) + run_command(prompt) break diff --git a/sgpt/utils.py b/sgpt/utils.py index d49af9a3..daf27f00 100644 --- a/sgpt/utils.py +++ b/sgpt/utils.py @@ -11,7 +11,7 @@ from sgpt.integration import bash_integration, zsh_integration -def get_edited_prompt() -> str: +def get_edited_prompt(prompt: str = "") -> str: """ Opens the user's default editor to let them input a prompt, and returns the edited text. @@ -21,6 +21,9 @@ def get_edited_prompt() -> str: with NamedTemporaryFile(suffix=".txt", delete=False) as file: # Create file and store path. file_path = file.name + if prompt: + file.write(prompt.encode("utf-8")) + file.close() editor = os.environ.get("EDITOR", "vim") # This will write text to file using $EDITOR. os.system(f"{editor} {file_path}") From 9d89d06f032d26c2224ff64de1bcd5740e77ade6 Mon Sep 17 00:00:00 2001 From: Eaad Date: Mon, 23 Sep 2024 16:52:31 +0300 Subject: [PATCH 2/3] Fix prompt text order in main function --- sgpt/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sgpt/app.py b/sgpt/app.py index fa78fb77..33ac3193 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -237,7 +237,7 @@ def main( while shell and interaction: option = typer.prompt( - text="[E]xecute, [D]escribe, [A]bort [M]odify", + text="[E]xecute, [D]escribe, [M]odify, [A]bort ", type=Choice(("e", "d", "a", "y", "m"), case_sensitive=False), default="e" if cfg.get("DEFAULT_EXECUTE_SHELL_CMD") == "true" else "a", show_choices=False, From 81fd730a9eab6fb6bd9c302f22c280652763a3ca Mon Sep 17 00:00:00 2001 From: Eaad Date: Mon, 23 Sep 2024 16:53:05 +0300 Subject: [PATCH 3/3] Fix prompt text spacing in main function --- sgpt/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sgpt/app.py b/sgpt/app.py index 33ac3193..874f6718 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -237,7 +237,7 @@ def main( while shell and interaction: option = typer.prompt( - text="[E]xecute, [D]escribe, [M]odify, [A]bort ", + text="[E]xecute, [D]escribe, [M]odify, [A]bort", type=Choice(("e", "d", "a", "y", "m"), case_sensitive=False), default="e" if cfg.get("DEFAULT_EXECUTE_SHELL_CMD") == "true" else "a", show_choices=False,