Skip to content
Snippets Groups Projects
Commit 885bd579 authored by Michael Aaron Murphy's avatar Michael Aaron Murphy
Browse files

Enable Redirecting Functions

Also enables background functions, but there's an issue with the shell hanging when a function is sent to te background
parent 9ba6961b
No related branches found
No related tags found
No related merge requests found
......@@ -17,3 +17,15 @@ fn format_with pat
end
echo one two three four five | format_with "-"
fn square
read x
echo $(( x * x ))
end
fn mult x
read y
echo $(( y * x ))
end
echo 5 | square | mult 3
......@@ -65,6 +65,13 @@ impl Pipeline {
stdout.file = expand_string(stdout.file.as_str(), expanders, false).join(" ");
}
}
pub fn requires_piping(&self) -> bool {
self.jobs.len() > 1 ||
self.stdin != None ||
self.stdout != None ||
self.jobs.last().unwrap().kind == JobKind::Background
}
}
impl fmt::Display for Pipeline {
......
......@@ -180,7 +180,7 @@ impl<'a> Shell<'a> {
builtins.get(key)
} {
// Run the 'main' of the command and set exit_status
if pipeline.jobs.len() == 1 && pipeline.stdin == None && pipeline.stdout == None {
if !pipeline.requires_piping() {
if self.flags & PRINT_COMMS != 0 { eprintln!("> {}", pipeline.to_string()); }
let borrowed = &pipeline.jobs[0].args;
let small: SmallVec<[&str; 4]> = borrowed.iter()
......@@ -192,7 +192,7 @@ impl<'a> Shell<'a> {
}
// Branch else if -> input == shell function and set the exit_status
} else if let Some(function) = self.functions.get(&pipeline.jobs[0].command).cloned() {
if pipeline.jobs.len() == 1 {
if !pipeline.requires_piping() {
let args: &[String] = pipeline.jobs[0].args.deref();
let args: Vec<&str> = args.iter().map(AsRef::as_ref).collect();
match function.execute(self, &args) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment