Skip to content

Commit

Permalink
Remove old code running method
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 committed Sep 9, 2024
1 parent 05381da commit 62c4d84
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/running_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 62c4d84

Please sign in to comment.