1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 23:02:06 +00:00

Shell: Implement program-aware autocompletion

A program can either respond to `--complete -- some args to complete`
directly, or add a `_complete_<program name>` invokable (i.e. shell
function, or just a plain binary in PATH) that completes the given
command and lists the completions on stdout.
Should such a completion fail or yield no results, we'll fall back to
the previous completion algorithm.
This commit is contained in:
Ali Mohammad Pur 2022-03-23 01:14:48 +04:30 committed by Ali Mohammad Pur
parent fc4d36ccd0
commit 7e4cc187d9
5 changed files with 315 additions and 47 deletions

View file

@ -408,7 +408,7 @@ RefPtr<AST::Node> Shell::immediate_filter_glob(AST::ImmediateExpression& invokin
if (value.size() == 1) {
if (!value.first().matches(glob))
return IterationDecision::Continue;
result.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1].position(), value.first()));
result.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1].position(), value.first(), AST::StringLiteral::EnclosureType::None));
return IterationDecision::Continue;
}
@ -416,7 +416,7 @@ RefPtr<AST::Node> Shell::immediate_filter_glob(AST::ImmediateExpression& invokin
if (entry.matches(glob)) {
NonnullRefPtrVector<AST::Node> nodes;
for (auto& string : value)
nodes.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1].position(), string));
nodes.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1].position(), string, AST::StringLiteral::EnclosureType::None));
result.append(AST::make_ref_counted<AST::ListConcatenate>(arguments[1].position(), move(nodes)));
return IterationDecision::Continue;
}
@ -450,7 +450,7 @@ RefPtr<AST::Node> Shell::immediate_join(AST::ImmediateExpression& invoking_node,
StringBuilder builder;
builder.join(delimiter_str, value->resolve_as_list(*this));
return AST::make_ref_counted<AST::StringLiteral>(invoking_node.position(), builder.to_string());
return AST::make_ref_counted<AST::StringLiteral>(invoking_node.position(), builder.to_string(), AST::StringLiteral::EnclosureType::None);
}
RefPtr<AST::Node> Shell::run_immediate_function(StringView str, AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector<AST::Node>& arguments)