diff --git a/sgpt/app.py b/sgpt/app.py index 733b7ce4..874f6718 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, [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, 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}")