Skip to content

Commit

Permalink
feat: support auto n to skip n confirmations (#346)
Browse files Browse the repository at this point in the history
* feat: limited number of confirmation skips

* chore: if/else minor refactor
  • Loading branch information
0xbrayo authored Dec 19, 2024
1 parent a9bd44f commit 7d2e9e7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions gptme/util/ask_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sys
import termios
import re
from collections.abc import Callable, Generator
from pathlib import Path

Expand All @@ -22,6 +23,7 @@

# Global state
override_auto = False
auto_skip_count = 0
copiable = False
editable = False

Expand Down Expand Up @@ -88,9 +90,11 @@ def ask_execute(question="Execute code?", default=True) -> bool:
Returns:
bool: True if user confirms execution, False otherwise
"""
global override_auto, copiable, editable
global override_auto, auto_skip_count, copiable, editable

if override_auto:
if override_auto or auto_skip_count > 0:
if auto_skip_count > 0:
auto_skip_count -= 1
return True

print_bell() # Ring the bell just before asking for input
Expand Down Expand Up @@ -128,9 +132,14 @@ def ask_execute(question="Execute code?", default=True) -> bool:
return ask_execute("Execute with changes?", default)
return False

# secret option to stop asking for the rest of the session
if answer == "auto":
return (override_auto := True)
re_auto = r"auto(?:\s+(\d+))?"
match = re.match(re_auto, answer)
if match:
if match.group(2):
auto_skip_count = int(match.group(2))
return True
else:
return (override_auto := True)

# secret option to ask for help
if answer in ["help", "h", "?"]:
Expand Down

0 comments on commit 7d2e9e7

Please sign in to comment.