diff --git a/Shell/AST.cpp b/Shell/AST.cpp index 96c74af619..fd2c0460b8 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -556,7 +556,7 @@ void Comment::dump(int level) const RefPtr Comment::run(RefPtr) { - return create(""); + return create({}); } void Comment::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata) @@ -1229,7 +1229,27 @@ void Sequence::dump(int level) const RefPtr Sequence::run(RefPtr shell) { + // If we are to return a job, block on the left one then return the right one. + if (would_execute()) { + RefPtr execute_node = create(m_left->position(), m_left); + auto left_job = execute_node->run(shell); + ASSERT(left_job->is_job()); + shell->block_on_job(static_cast(left_job.ptr())->job()); + + if (m_right->would_execute()) + return m_right->run(shell); + + execute_node = create(m_right->position(), m_right); + return execute_node->run(shell); + } auto left = m_left->run(shell)->resolve_as_commands(shell); + // This could happen if a comment is next to a command. + if (left.size() == 1) { + auto& command = left.first(); + if (command.argv.is_empty() && command.redirections.is_empty()) + return m_right->run(shell); + } + auto right = m_right->run(shell)->resolve_as_commands(shell); Vector commands; diff --git a/Shell/AST.h b/Shell/AST.h index c5f193bf53..4c30150a84 100644 --- a/Shell/AST.h +++ b/Shell/AST.h @@ -699,6 +699,7 @@ private: virtual HitTestResult hit_test_position(size_t) override; virtual String class_name() const override { return "Sequence"; } virtual bool is_list() const override { return true; } + virtual bool would_execute() const override { return m_left->would_execute() || m_right->would_execute(); } RefPtr m_left; RefPtr m_right; diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp index 7e6f985e17..70357de132 100644 --- a/Shell/Parser.cpp +++ b/Shell/Parser.cpp @@ -717,9 +717,6 @@ RefPtr Parser::parse_comment() consume(); auto text = consume_while(is_not('\n')); - if (peek() == '\n') - consume(); - return create(move(text)); // Comment } diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 8b00e04f25..622dbf5478 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -316,9 +316,6 @@ int Shell::run_command(const StringView& cmd) if (cmd.is_empty()) return 0; - if (cmd.starts_with("#")) - return 0; - auto command = Parser(cmd).parse(); if (!command) @@ -505,6 +502,8 @@ bool Shell::run_file(const String& filename, bool explicitly_invoked) if (file_result.is_error()) { if (explicitly_invoked) fprintf(stderr, "Failed to open %s: %s\n", filename.characters(), file_result.error().characters()); + else + dbg() << "open() failed for '" << filename << "' with " << file_result.error(); return false; } auto file = file_result.value();