diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 5313ac52c4..3eaeccec4b 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -950,6 +950,17 @@ void Shell::restore_ios() tcsetpgrp(STDIN_FILENO, m_pid); } +void Shell::block_on_pipeline(RefPtr pipeline) +{ + if (!pipeline) + return; + + for (auto& it : jobs) { + if (auto cmd = it.value->command_ptr(); cmd->pipeline == pipeline && cmd->is_pipe_source) + block_on_job(it.value); + } +} + void Shell::block_on_job(RefPtr job) { TemporaryChange current_job { m_current_job, job.ptr() }; @@ -977,6 +988,10 @@ void Shell::block_on_job(RefPtr job) return; loop.exec(); + + // If the job is part of a pipeline, wait for the rest of the members too. + if (auto command = job->command_ptr()) + block_on_pipeline(command->pipeline); } String Shell::get_history_path() diff --git a/Shell/Shell.h b/Shell/Shell.h index fc0b5258dd..65d49cff91 100644 --- a/Shell/Shell.h +++ b/Shell/Shell.h @@ -89,6 +89,7 @@ public: bool run_builtin(const AST::Command&, const NonnullRefPtrVector&, int& retval); bool has_builtin(const StringView&) const; void block_on_job(RefPtr); + void block_on_pipeline(RefPtr); String prompt() const; static String expand_tilde(const String&);