From b8b87e6517ed4aeabeea347b668bada84ae05338 Mon Sep 17 00:00:00 2001 From: konstantin-goldman <47669472+konstantin-goldman@users.noreply.github.com> Date: Sat, 20 May 2023 10:10:20 -0700 Subject: [PATCH] Configuration parameter to execute shell commands by default (#246) --- README.md | 2 ++ sgpt/app.py | 9 ++++++++- sgpt/config.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b41447..dceba08 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,8 @@ DEFAULT_MODEL=gpt-3.5-turbo DEFAULT_COLOR=magenta # Force use system role messages (not recommended). SYSTEM_ROLES=false +# When in --shell mode, default to "Y" for no input. +DEFAULT_EXECUTE_SHELL_CMD=false ``` Possible options for `DEFAULT_COLOR`: black, red, green, yellow, blue, magenta, cyan, white, bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white. diff --git a/sgpt/app.py b/sgpt/app.py index ae4b89d..662733f 100644 --- a/sgpt/app.py +++ b/sgpt/app.py @@ -175,7 +175,14 @@ def main( caching=cache, ) - if shell and not stdin_passed and typer.confirm("Execute shell command?"): + if ( + shell + and not stdin_passed + and typer.confirm( + text="Execute shell command?", + default=cfg.get("DEFAULT_EXECUTE_SHELL_CMD") == "true", + ) + ): run_command(full_completion) diff --git a/sgpt/config.py b/sgpt/config.py index 0f9160c..50c32fc 100644 --- a/sgpt/config.py +++ b/sgpt/config.py @@ -28,6 +28,7 @@ DEFAULT_CONFIG = { "DEFAULT_COLOR": os.getenv("DEFAULT_COLOR", "magenta"), "ROLE_STORAGE_PATH": os.getenv("ROLE_STORAGE_PATH", str(ROLE_STORAGE_PATH)), "SYSTEM_ROLES": os.getenv("SYSTEM_ROLES", "false"), + "DEFAULT_EXECUTE_SHELL_CMD": os.getenv("DEFAULT_EXECUTE_SHELL_CMD", "false"), # New features might add their own config variables here. }