1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:17:42 +00:00

Shell: Add the alias builtin and resolve aliases

This follows the other shells in alias resolution, and resolves the
alias only once.
This commit is contained in:
AnotherTest 2020-06-17 18:51:44 +04:30 committed by Andreas Kling
parent a4627f2439
commit 2915dcfcc3
4 changed files with 66 additions and 1 deletions

View file

@ -617,7 +617,30 @@ RefPtr<Value> Execute::run(TheExecutionInputType input_value)
RefPtr<Job> job;
auto shell = input_value;
auto commands = m_command->run(input_value)->resolve_as_commands(input_value);
auto initial_commands = m_command->run(input_value)->resolve_as_commands(input_value);
decltype(initial_commands) commands;
for (auto& command : initial_commands) {
if (!command.argv.is_empty()) {
auto alias = shell->resolve_alias(command.argv[0]);
if (!alias.is_null()) {
auto argv0 = command.argv.take_first();
auto subcommand_ast = Parser { alias }.parse();
if (subcommand_ast) {
while (subcommand_ast->is_execute()) {
auto* ast = static_cast<Execute*>(subcommand_ast.ptr());
subcommand_ast = ast->command();
}
RefPtr<Node> substitute = adopt(*new Join(position(), move(subcommand_ast), adopt(*new CommandLiteral(position(), command))));
commands.append(substitute->run(input_value)->resolve_as_commands(input_value));
} else {
commands.append(command);
}
} else {
commands.append(command);
}
}
}
Vector<RefPtr<Job>> jobs_to_wait_for;
auto run_commands = [&](auto& commands) {