From 07c070745fb402eed0d7e3ec1567edfabb9b9946 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 8 Jun 2020 11:06:51 +0430 Subject: [PATCH] ls: Emit plain text when output is not a tty --- Userland/ls.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/ls.cpp b/Userland/ls.cpp index c1fb436b797..0e369d900e6 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -49,7 +49,7 @@ static int do_file_system_object_long(const char* path); static int do_file_system_object_short(const char* path); -static bool flag_colorize = true; +static bool flag_colorize = false; static bool flag_long = false; static bool flag_show_dotfiles = false; static bool flag_show_inode = false; @@ -80,6 +80,11 @@ int main(int argc, char** argv) terminal_columns = ws.ws_col; output_is_terminal = true; } + if (!isatty(STDOUT_FILENO)) { + flag_disable_hyperlinks = true; + } else { + flag_colorize = true; + } if (pledge("stdio rpath", nullptr) < 0) { perror("pledge"); @@ -300,7 +305,6 @@ bool print_filesystem_object(const String& path, const String& name, const struc printf(" %4u,%4u ", major(st.st_rdev), minor(st.st_rdev)); } else { if (flag_human_readable) { - ASSERT(st.st_size > 0); printf(" %10s ", human_readable_size((size_t)st.st_size).characters()); } else { printf(" %10zd ", st.st_size);