From fc6c01a9a5e1a8fcdfc2dfb084d8e60675dc6c4d Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 29 Oct 2024 12:41:01 -0700 Subject: [PATCH] feat: add command to load and execute commands from file --- aider/commands.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index 4d7c1073a..edc0490fb 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -771,7 +771,6 @@ class Commands: all_files = [self.quote_fname(fn) for fn in all_files] return all_files - # ai add cmd_load which takes a filename. read `/commands` from each line an execute them! def cmd_drop(self, args=""): "Remove files from the chat session to free up context space" @@ -1247,6 +1246,30 @@ class Commands: output = f"{announcements}\n{settings}" self.io.tool_output(output) + def cmd_load(self, args): + "Load and execute commands from a file" + if not args.strip(): + self.io.tool_error("Please provide a filename containing commands to load.") + return + + try: + with open(args.strip(), 'r') as f: + commands = f.readlines() + except FileNotFoundError: + self.io.tool_error(f"File not found: {args}") + return + except Exception as e: + self.io.tool_error(f"Error reading file: {e}") + return + + for cmd in commands: + cmd = cmd.strip() + if not cmd or cmd.startswith('#'): + continue + + self.io.tool_output(f"\nExecuting command: {cmd}") + self.run(cmd) + def cmd_copy(self, args): "Copy the last assistant message to the clipboard" all_messages = self.coder.done_messages + self.coder.cur_messages