@@ -3843,9 +3843,7 @@ async def handle_shell_commands(self, commands_str, group):
38433843 if not command or command .startswith ("#" ):
38443844 continue
38453845
3846- if command and getattr (self .args , "command_prefix" , None ):
3847- command_prefix = getattr (self .args , "command_prefix" , None )
3848- command = f"{ command_prefix } { command } "
3846+ command = self .format_command_with_prefix (command )
38493847
38503848 self .io .tool_output ()
38513849 self .io .tool_output (f"Running { command } " )
@@ -3864,3 +3862,32 @@ async def handle_shell_commands(self, commands_str, group):
38643862 line_plural = "line" if num_lines == 1 else "lines"
38653863 self .io .tool_output (f"Added { num_lines } { line_plural } of output to the chat." )
38663864 return accumulated_output
3865+
3866+ def format_command_with_prefix (self , command ):
3867+ """
3868+ Format a command with a command prefix.
3869+
3870+ If the command prefix contains a {} placeholder, replace it with the command.
3871+ Otherwise, append the command to the prefix with a space.
3872+
3873+ Args:
3874+ command (str): The command to format
3875+
3876+ Returns:
3877+ str: The formatted command
3878+ """
3879+ command_prefix = None
3880+
3881+ if command and getattr (self .args , "command_prefix" , None ):
3882+ command_prefix = getattr (self .args , "command_prefix" , None )
3883+
3884+ if not command_prefix :
3885+ return command
3886+
3887+ # Check if the prefix contains a {} placeholder
3888+ if "{}" in command_prefix :
3889+ # Replace the {} placeholder with the command
3890+ return command_prefix .replace ("{}" , command )
3891+ else :
3892+ # Append the command to the prefix with a space
3893+ return f"{ command_prefix } { command } "
0 commit comments