diff --git a/src/complete.cpp b/src/complete.cpp index c3d2aae86..2707931fd 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -39,6 +39,7 @@ #include "history.h" #include "iothread.h" #include "parse_constants.h" +#include "parser_keywords.h" #include "parse_util.h" #include "parser.h" #include "path.h" @@ -1473,17 +1474,8 @@ void completer_t::perform() { // Hack: fix autosuggestion by removing prefixing "and"s #6249. if (flags & completion_request_t::autosuggestion) { - constexpr const wchar_t *prefix_cmds[] = {L"and", L"begin", L"command", L"exec", - L"if", L"not", L"or", L"while"}; - while (!tokens.empty()) { - auto cmd_string = tokens.front().get_source(cmd); - bool is_subcommand = std::find_if(std::begin(prefix_cmds), std::end(prefix_cmds), - [&cmd_string](const wchar_t *prefix) { - return cmd_string == prefix; - }) != std::end(prefix_cmds); - if (!is_subcommand) break; + while (!tokens.empty() && parser_keywords_is_subcommand(tokens.front().get_source(cmd))) tokens.erase(tokens.begin()); - } } // Empty process (cursor is after one of ;, &, |, \n, &&, || modulo whitespace). if (tokens.empty()) { diff --git a/src/parser_keywords.cpp b/src/parser_keywords.cpp index 7c0c4065c..aae7b91b2 100644 --- a/src/parser_keywords.cpp +++ b/src/parser_keywords.cpp @@ -17,7 +17,8 @@ static const wcstring skip_keywords[]{ }; static const wcstring subcommand_keywords[]{L"command", L"builtin", L"while", L"exec", - L"if", L"and", L"or", L"not"}; + L"if", L"and", L"or", L"not", + L"time", L"begin"}; static const string_set_t block_keywords = {L"for", L"while", L"if", L"function", L"switch", L"begin"};