diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-10-28 17:20:42 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-29 11:53:01 +0100 |
commit | 384e872ff9a4e35b3cb018be58b7632e063eb2b8 (patch) | |
tree | b2a44fc7e05afd01003aad5aae93128da23fd16b /Shell | |
parent | a46318d414a30c3f30517795b8737600bed91486 (diff) | |
download | serenity-384e872ff9a4e35b3cb018be58b7632e063eb2b8.zip |
Shell: Add redirections to the formatted command string
Diffstat (limited to 'Shell')
-rw-r--r-- | Shell/AST.cpp | 50 | ||||
-rw-r--r-- | Shell/Shell.cpp | 2 |
2 files changed, 45 insertions, 7 deletions
diff --git a/Shell/AST.cpp b/Shell/AST.cpp index 19501e99d8..f6dd6484b5 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -50,12 +50,50 @@ void AK::Formatter<Shell::AST::Command>::format(TypeErasedFormatParams&, FormatB if (m_width != value_not_set && m_precision != value_not_set) ASSERT_NOT_REACHED(); - bool first = true; - for (auto& arg : value.argv) { - if (!first) - builder.put_literal(" "); - first = false; - builder.put_literal(arg); + if (value.argv.is_empty()) { + builder.put_literal("(ShellInternal)"); + } else { + bool first = true; + for (auto& arg : value.argv) { + if (!first) + builder.put_literal(" "); + first = false; + builder.put_literal(arg); + } + } + + for (auto& redir : value.redirections) { + builder.put_padding(' ', 1); + if (redir.is_path_redirection()) { + auto path_redir = (const Shell::AST::PathRedirection*)&redir; + builder.put_i64(path_redir->fd); + switch (path_redir->direction) { + case Shell::AST::PathRedirection::Read: + builder.put_literal("<"); + break; + case Shell::AST::PathRedirection::Write: + builder.put_literal(">"); + break; + case Shell::AST::PathRedirection::WriteAppend: + builder.put_literal(">>"); + break; + case Shell::AST::PathRedirection::ReadWrite: + builder.put_literal("<>"); + break; + } + builder.put_literal(path_redir->path); + } else if (redir.is_fd_redirection()) { + auto* fdredir = (const Shell::AST::FdRedirection*)&redir; + builder.put_i64(fdredir->new_fd); + builder.put_literal(">"); + builder.put_i64(fdredir->old_fd); + } else if (redir.is_close_redirection()) { + auto close_redir = (const Shell::AST::CloseRedirection*)&redir; + builder.put_i64(close_redir->fd); + builder.put_literal(">&-"); + } else { + ASSERT_NOT_REACHED(); + } } if (!value.next_chain.is_empty()) { diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index c161c7f020..8c787f3b84 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -563,7 +563,7 @@ RefPtr<Job> Shell::run_command(const AST::Command& command) FileDescriptionCollector fds; if (options.verbose) - warnln("+ {}", m_pid, command); + warnln("+ {}", command); // If the command is empty, store the redirections and apply them to all later commands. if (command.argv.is_empty() && !command.should_immediately_execute_next) { |