Skip to content

Commit 889247d

Browse files
committed
#215: Use semicolons as command separators, not lines
1 parent 828d7ab commit 889247d

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

aider/coders/base_coder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3804,7 +3804,7 @@ async def run_shell_commands(self):
38043804
self.commands.cmd_running = False
38053805

38063806
async def handle_shell_commands(self, commands_str, group):
3807-
commands = commands_str.strip().splitlines()
3807+
commands = commands_str.strip().split(";")
38083808
command_count = sum(
38093809
1 for cmd in commands if cmd.strip() and not cmd.strip().startswith("#")
38103810
)

aider/run_cmd.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def run_cmd_subprocess(command, verbose=False, cwd=None, encoding=sys.stdout.enc
6060
print("Parent process:", parent_process)
6161

6262
process = subprocess.Popen(
63-
command,
63+
process_multiline_command(command),
6464
stdout=subprocess.PIPE,
6565
stderr=subprocess.STDOUT,
6666
text=True,
@@ -131,3 +131,27 @@ def output_callback(b):
131131
except (pexpect.ExceptionPexpect, TypeError, ValueError) as e:
132132
error_msg = f"Error running command {command}: {e}"
133133
return 1, error_msg
134+
135+
136+
def process_multiline_command(command_string):
137+
"""
138+
Removes lines that end with a single backslash used for line continuation.
139+
"""
140+
lines = command_string.splitlines()
141+
processed_lines = []
142+
143+
for line in lines:
144+
# rstrip() removes trailing whitespace, including newlines in the original splitlines context.
145+
# We check if the line, stripped of whitespace, ends with a single backslash.
146+
stripped_line = line.rstrip()
147+
148+
# We need to distinguish between 'foo\' and 'foo\\' (literal backslash)
149+
if stripped_line.endswith("\\") and not stripped_line.endswith("\\\\"):
150+
# This line ends in an unescaped backslash (line continuation), so we skip it.
151+
continue
152+
else:
153+
processed_lines.append(line)
154+
155+
# Join the remaining lines with the appropriate newline character
156+
# Use '\n'.join for consistent Unix-style newlines, or os.linesep
157+
return "\n".join(processed_lines)

0 commit comments

Comments
 (0)