diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-07-12 06:50:54 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-12 17:45:18 +0200 |
commit | 8d71eb9a6c09fde104fb7637b45035ff79a96dce (patch) | |
tree | 286090eaf3d46a13b67a47258e1ee36a8725e80b /Shell | |
parent | e461e3c8b060c2edd7af06b77acf48f196057ea5 (diff) | |
download | serenity-8d71eb9a6c09fde104fb7637b45035ff79a96dce.zip |
Shell: Recursively resolve aliases
Diffstat (limited to 'Shell')
-rw-r--r-- | Shell/AST.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Shell/AST.cpp b/Shell/AST.cpp index 121530c66a..4bbf3777ba 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -745,7 +745,7 @@ RefPtr<Value> Execute::run(RefPtr<Shell> shell) auto initial_commands = m_command->run(shell)->resolve_as_commands(shell); decltype(initial_commands) commands; - for (auto& command : initial_commands) { + Function<void(Command&)> resolve_aliases_and_append = [&](auto& command) { if (!command.argv.is_empty()) { auto alias = shell->resolve_alias(command.argv[0]); if (!alias.is_null()) { @@ -757,15 +757,26 @@ RefPtr<Value> Execute::run(RefPtr<Shell> shell) subcommand_ast = ast->command(); } RefPtr<Node> substitute = create<Join>(position(), move(subcommand_ast), create<CommandLiteral>(position(), command)); - commands.append(substitute->run(shell)->resolve_as_commands(shell)); + for (auto& subst_command : substitute->run(shell)->resolve_as_commands(shell)) { + if (!subst_command.argv.is_empty() && subst_command.argv.first() == argv0) // Disallow an alias resolving to itself. + commands.append(subst_command); + else + resolve_aliases_and_append(subst_command); + } } else { commands.append(command); } } else { commands.append(command); } + } else { + commands.append(command); } - } + }; + + for (auto& command : initial_commands) + resolve_aliases_and_append(command); + Vector<RefPtr<Job>> jobs_to_wait_for; auto run_commands = [&](auto& commands) { |