diff --git a/src/shell/job.rs b/src/shell/job.rs index 6f5c05b63eb3cc10db8418c4ac348758cf6093c9..02d75ae2ec2fb9cb7b59c67110f8f166987b1ab9 100644 --- a/src/shell/job.rs +++ b/src/shell/job.rs @@ -44,40 +44,23 @@ impl Job { self.command = self.args.first().map_or("".into(), |c| c.clone().into()); } - pub fn build_command(&mut self) -> Command { - match CommandType::from(self.command.as_ref()) { - CommandType::Builtin => { - use std::env; - let process = env::current_exe().unwrap(); - let mut command = Command::new(process); - command.arg("-c"); - command.arg(&self.command); - for arg in self.args.drain().skip(1) { - command.arg(arg); - } - command - }, - CommandType::External => { - let mut command = Command::new(&self.command); - for arg in self.args.drain().skip(1) { - command.arg(arg); - } - command - } + pub fn build_command_external(&mut self) -> Command { + let mut command = Command::new(&self.command); + for arg in self.args.drain().skip(1) { + command.arg(arg); } + command } -} - -enum CommandType { - Builtin, - External -} -impl<'a> From<&'a str> for CommandType { - fn from(command: &'a str) -> CommandType { - match command { - "help" | "history" | "echo" | "test" | "calc" => CommandType::Builtin, - _ => CommandType::External + pub fn build_command_builtin(&mut self) -> Command { + use std::env; + let process = env::current_exe().unwrap(); + let mut command = Command::new(process); + command.arg("-c"); + command.arg(&self.command); + for arg in self.args.drain().skip(1) { + command.arg(arg); } + command } } diff --git a/src/shell/pipe.rs b/src/shell/pipe.rs index 05604bfff04d3589d581043283daa0dc5e3499c4..a76ffedf0e7eb4e121e5360f600f01ab2f5642f7 100644 --- a/src/shell/pipe.rs +++ b/src/shell/pipe.rs @@ -174,7 +174,11 @@ impl<'a> PipelineExecution for Shell<'a> { // Generate a list of commands from the given pipeline let mut piped_commands: Vec<(Command, JobKind)> = pipeline.jobs .drain(..).map(|mut job| { - (job.build_command(), job.kind) + if self.builtins.contains_key(&job.command.as_ref()) { + (job.build_command_builtin(), job.kind) + } else { + (job.build_command_external(), job.kind) + } }).collect(); match pipeline.stdin { None => (),