diff options
author | Jagger De Leo <jcdl@fastmail.com> | 2021-04-17 16:43:45 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-18 00:54:39 +0200 |
commit | cebd3f740b6fd2fd0da30ed92310a968cf6df44a (patch) | |
tree | bf9d886b2965f61c632b914aa17866148f04802e /Userland/Utilities | |
parent | 0d4912826b990e3a416ede908502d5a7e3c6ae31 (diff) | |
download | serenity-cebd3f740b6fd2fd0da30ed92310a968cf6df44a.zip |
ls: Remove extra spaces after filenames when piping
Fixes #5671
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/ls.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Userland/Utilities/ls.cpp b/Userland/Utilities/ls.cpp index 218fabedd6..a9b91f6813 100644 --- a/Userland/Utilities/ls.cpp +++ b/Userland/Utilities/ls.cpp @@ -75,6 +75,8 @@ static bool output_is_terminal = false; static HashMap<uid_t, String> users; static HashMap<gid_t, String> groups; +static bool is_a_tty = false; + int main(int argc, char** argv) { if (pledge("stdio rpath tty", nullptr) < 0) { @@ -89,7 +91,9 @@ int main(int argc, char** argv) terminal_columns = ws.ws_col; output_is_terminal = true; } - if (!isatty(STDOUT_FILENO)) { + + is_a_tty = isatty(STDOUT_FILENO); + if (!is_a_tty) { flag_disable_hyperlinks = true; } else { flag_colorize = true; @@ -483,8 +487,10 @@ static bool print_names(const char* path, size_t longest_name, const Vector<Stri size_t column_width = longest_name + max(offset, 2); printed_on_row += column_width; - for (size_t j = nprinted; i != (names.size() - 1) && j < column_width; ++j) - printf(" "); + if (is_a_tty) { + for (size_t j = nprinted; i != (names.size() - 1) && j < column_width; ++j) + printf(" "); + } if ((printed_on_row + column_width) >= terminal_columns) { printf("\n"); printed_on_row = 0; |