diff --git a/Base/usr/share/man/man1/ls.md b/Base/usr/share/man/man1/ls.md index 6902976fb1..3067832913 100644 --- a/Base/usr/share/man/man1/ls.md +++ b/Base/usr/share/man/man1/ls.md @@ -32,6 +32,7 @@ If no *path* argument is provided the current working directory is used. * `-h`, `--human-readable`: Print human-readable sizes * `-K`, `--no-hyperlinks`: Disable hyperlinks * `-R`, `--recursive`: List subdirectories recursively +* `-1`: List one file per line ## Arguments diff --git a/Userland/Utilities/ls.cpp b/Userland/Utilities/ls.cpp index 4fe2289ce0..30fa3a9a96 100644 --- a/Userland/Utilities/ls.cpp +++ b/Userland/Utilities/ls.cpp @@ -64,6 +64,7 @@ static bool flag_sort_by_timestamp = false; static bool flag_reverse_sort = false; static bool flag_disable_hyperlinks = false; static bool flag_recursive = false; +static bool flag_force_newline = false; static size_t terminal_rows = 0; static size_t terminal_columns = 0; @@ -117,6 +118,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(flag_human_readable, "Print human-readable sizes", "human-readable", 'h'); args_parser.add_option(flag_disable_hyperlinks, "Disable hyperlinks", "no-hyperlinks", 'K'); args_parser.add_option(flag_recursive, "List subdirectories recursively", "recursive", 'R'); + args_parser.add_option(flag_force_newline, "List one file per line", nullptr, '1'); args_parser.add_positional_argument(paths, "Directory to list", "path", Core::ArgsParser::Required::No); args_parser.parse(arguments); @@ -480,7 +482,7 @@ static bool print_names(const char* path, size_t longest_name, const Vector= terminal_columns) { + if ((printed_on_row + column_width) >= terminal_columns || flag_force_newline) { printf("\n"); printed_on_row = 0; }