Skip to content

Commit

Permalink
Merge pull request AbanteAI#26 from kvaky/keep-cmd-history
Browse files Browse the repository at this point in the history
Add command history
  • Loading branch information
jakethekoenig authored Feb 5, 2024
2 parents 7b20e78 + fd2ed16 commit d33af5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rawdog/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import argparse
import io
import readline

from contextlib import redirect_stdout

from rawdog.llm_client import LLMClient
from rawdog.utils import history_file


llm_client = LLMClient() # Will prompt for API key if not found
Expand Down Expand Up @@ -65,6 +67,10 @@ def main():
parser.add_argument('--dry-run', action='store_true', help='Print the script before executing and prompt for confirmation.')
args = parser.parse_args()

if history_file.exists():
readline.read_history_file(history_file)
readline.set_history_length(1000)

if len(args.prompt) > 0:
rawdog(" ".join(args.prompt))
else:
Expand All @@ -73,6 +79,8 @@ def main():
try:
print("\nWhat can I do for you? (Ctrl-C to exit)")
prompt = input("> ")
# Save history after each command to avoid losing it in case of crash
readline.write_history_file(history_file)
print("")
rawdog(prompt, verbose=args.dry_run)
except KeyboardInterrupt:
Expand Down
2 changes: 2 additions & 0 deletions src/rawdog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
rawdog_dir = Path.home() / ".rawdog"
rawdog_dir.mkdir(exist_ok=True)

# Command history file
history_file = rawdog_dir / "cmdline_history"

# Config
config_path = rawdog_dir / "config.yaml"
Expand Down

0 comments on commit d33af5a

Please sign in to comment.