Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modify option before executing shell commands #628

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sgpt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -256,6 +256,9 @@ def main(
functions=function_schemas,
)
continue
elif option == "m":
prompt = get_edited_prompt(full_completion)
run_command(prompt)
break


Expand Down
5 changes: 4 additions & 1 deletion sgpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}")
Expand Down