diff --git a/Userland/Shell/Parser.cpp b/Userland/Shell/Parser.cpp index 2cef5bb3c5..9aa052d3cc 100644 --- a/Userland/Shell/Parser.cpp +++ b/Userland/Shell/Parser.cpp @@ -1118,7 +1118,7 @@ RefPtr Parser::parse_expression() return read_concat(create(move(list))); // Cast To List } - if (starting_char == '!') { + if (starting_char == '!' && m_in_interactive_mode) { if (auto designator = parse_history_designator()) return designator; } diff --git a/Userland/Shell/Parser.h b/Userland/Shell/Parser.h index 6b8218865a..c699c0eb66 100644 --- a/Userland/Shell/Parser.h +++ b/Userland/Shell/Parser.h @@ -37,8 +37,9 @@ namespace Shell { class Parser { public: - Parser(StringView input) + Parser(StringView input, bool interactive = false) : m_input(move(input)) + , m_in_interactive_mode(interactive) { } @@ -163,6 +164,7 @@ private: Vector m_extra_chars_not_allowed_in_barewords; bool m_is_in_brace_expansion_spec { false }; bool m_continuation_controls_allowed { false }; + bool m_in_interactive_mode { false }; }; #if 0 diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 23169a8cf2..47f99f653e 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -562,7 +562,7 @@ int Shell::run_command(const StringView& cmd, Optional source_po if (cmd.is_empty()) return 0; - auto command = Parser(cmd).parse(); + auto command = Parser(cmd, m_is_interactive).parse(); if (!command) return 0; @@ -1289,7 +1289,7 @@ void Shell::add_entry_to_cache(const String& entry) void Shell::highlight(Line::Editor& editor) const { auto line = editor.line(); - Parser parser(line); + Parser parser(line, m_is_interactive); auto ast = parser.parse(); if (!ast) return; @@ -1300,7 +1300,7 @@ Vector Shell::complete() { auto line = m_editor->line(m_editor->cursor()); - Parser parser(line); + Parser parser(line, m_is_interactive); auto ast = parser.parse(); @@ -1562,7 +1562,7 @@ bool Shell::has_history_event(StringView source) bool has_history_event { false }; } visitor; - Parser { source }.parse()->visit(visitor); + Parser { source, true }.parse()->visit(visitor); return visitor.has_history_event; } diff --git a/Userland/Shell/Shell.h b/Userland/Shell/Shell.h index 08f8f89c04..fb97a71cdd 100644 --- a/Userland/Shell/Shell.h +++ b/Userland/Shell/Shell.h @@ -128,8 +128,8 @@ public: RefPtr editor() const { return m_editor; } struct LocalFrame { - LocalFrame(const String& name, HashMap> variables) - : name(name) + LocalFrame(String name, HashMap> variables) + : name(move(name)) , local_variables(move(variables)) { } @@ -243,7 +243,7 @@ public: return err; } void possibly_print_error() const; - bool is_control_flow(ShellError error) + static bool is_control_flow(ShellError error) { switch (error) { case ShellError::InternalControlFlowBreak: