diff --git a/src/running_command.rs b/src/running_command.rs index 0fd9f615a..f423991d4 100644 --- a/src/running_command.rs +++ b/src/running_command.rs @@ -131,41 +131,24 @@ impl RunningCommand { // Create a new command that runs all the selected commands let mut cmd: CommandBuilder = CommandBuilder::new("sh"); - cmd.arg("-c"); - // Check if commands vector has more than one command - match commands.len() { - 1 => match commands[0].clone() { - Command::Raw(prompt) => cmd.arg(prompt), + let mut script = String::new(); // Initialize an empty string to hold the merged commands + for command in commands { + match command { + Command::Raw(prompt) => script.push_str(&format!("{}\n", prompt)), // Merge raw commands Command::LocalFile(file) => { - cmd.arg(&file); if let Some(parent) = file.parent() { - cmd.cwd(parent); + script.push_str(&format!("cd {}\n", parent.display())); + // Merge local file path } + script.push_str(&format!("sh {}\n", file.display())); + // Get the file path and append to the string } Command::None => panic!("Command::None was treated as a command"), - }, - - _ => { - let mut script = String::new(); // Initialize an empty string to hold the merged commands - for command in commands { - match command { - Command::Raw(prompt) => script.push_str(&format!("{}\\\n", prompt)), // Merge raw commands - Command::LocalFile(file) => { - if let Some(parent) = file.parent() { - script.push_str(&format!("cd {}\n", parent.display())); - // Merge local file path - } - script.push_str(&format!("{} {}\n", "sh", file.display())); - // Get the file path and append to the string - } - Command::None => panic!("Command::None was treated as a command"), - } - } - cmd.arg(script); // All the merged commands are passed as a single arguement to reduce the overhead of rebuilding the command arguments for each and every command } } + cmd.arg(script); // All the merged commands are passed as a single arguement to reduce the overhead of rebuilding the command arguments for each and every command // Open a pseudo-terminal with initial size let pair = pty_system