mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
Shell: Add redirections to the formatted command string
This commit is contained in:
parent
a46318d414
commit
384e872ff9
Notes:
sideshowbarker
2024-07-19 01:39:52 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/384e872ff9a Pull-request: https://github.com/SerenityOS/serenity/pull/3858
@ -50,6 +50,9 @@ void AK::Formatter<Shell::AST::Command>::format(TypeErasedFormatParams&, FormatB
|
||||
if (m_width != value_not_set && m_precision != value_not_set)
|
||||
ASSERT_NOT_REACHED();
|
||||
|
||||
if (value.argv.is_empty()) {
|
||||
builder.put_literal("(ShellInternal)");
|
||||
} else {
|
||||
bool first = true;
|
||||
for (auto& arg : value.argv) {
|
||||
if (!first)
|
||||
@ -57,6 +60,41 @@ void AK::Formatter<Shell::AST::Command>::format(TypeErasedFormatParams&, FormatB
|
||||
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()) {
|
||||
for (auto& command : value.next_chain) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user