1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:17:44 +00:00

ls: Add the -p option to append a trailing slash to directories

This overrides the `-F` option and vice-versa.
This commit is contained in:
Tim Ledbetter 2023-09-25 22:37:30 +01:00 committed by Andreas Kling
parent 6820e0e175
commit ba40526db2
2 changed files with 16 additions and 5 deletions

View file

@ -21,6 +21,7 @@ If no *path* argument is provided the current working directory is used.
* `-A`: Do not list implied . and .. directories * `-A`: Do not list implied . and .. directories
* `-B`, `--ignore-backups`: Do not list implied entries ending with ~ * `-B`, `--ignore-backups`: Do not list implied entries ending with ~
* `-F`, `--classify`: Append a file type indicator to entries * `-F`, `--classify`: Append a file type indicator to entries
* `-p`: Append a '/' indicator to directories
* `-d`, `--directory`: List directories themselves, not their contents * `-d`, `--directory`: List directories themselves, not their contents
* `-l`, `--long`: Display long info * `-l`, `--long`: Display long info
* `-t`: Sort files by timestamp (newest first) * `-t`: Sort files by timestamp (newest first)

View file

@ -49,6 +49,15 @@ enum class FieldToSortBy {
Size Size
}; };
enum class IndicatorStyle {
None = 0,
Directory = 1 << 0,
Executable = 1 << 1,
SymbolicLink = 1 << 2,
Classify = Directory | Executable | SymbolicLink
};
AK_ENUM_BITWISE_OPERATORS(IndicatorStyle)
static int do_file_system_object_long(DeprecatedString const& path); static int do_file_system_object_long(DeprecatedString const& path);
static int do_file_system_object_short(DeprecatedString const& path); static int do_file_system_object_short(DeprecatedString const& path);
@ -56,7 +65,7 @@ static bool print_names(char const* path, size_t longest_name, Vector<FileMetada
static bool filemetadata_comparator(FileMetadata& a, FileMetadata& b); static bool filemetadata_comparator(FileMetadata& a, FileMetadata& b);
static bool flag_classify = false; static IndicatorStyle flag_indicator_style = IndicatorStyle::None;
static bool flag_colorize = false; static bool flag_colorize = false;
static bool flag_long = false; static bool flag_long = false;
static bool flag_show_dotfiles = false; static bool flag_show_dotfiles = false;
@ -117,7 +126,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(flag_sort_by, FieldToSortBy::ModifiedAt, "Sort files by timestamp (newest first)", nullptr, 't'); args_parser.add_option(flag_sort_by, FieldToSortBy::ModifiedAt, "Sort files by timestamp (newest first)", nullptr, 't');
args_parser.add_option(flag_sort_by, FieldToSortBy::Size, "Sort files by size (largest first)", nullptr, 'S'); args_parser.add_option(flag_sort_by, FieldToSortBy::Size, "Sort files by size (largest first)", nullptr, 'S');
args_parser.add_option(flag_reverse_sort, "Reverse sort order", "reverse", 'r'); args_parser.add_option(flag_reverse_sort, "Reverse sort order", "reverse", 'r');
args_parser.add_option(flag_classify, "Append a file type indicator to entries", "classify", 'F'); args_parser.add_option(flag_indicator_style, IndicatorStyle::Classify, "Append a file type indicator to entries", "classify", 'F');
args_parser.add_option(flag_indicator_style, IndicatorStyle::Directory, "Append a '/' indicator to directories", nullptr, 'p');
args_parser.add_option(flag_colorize, "Use pretty colors", nullptr, 'G'); args_parser.add_option(flag_colorize, "Use pretty colors", nullptr, 'G');
args_parser.add_option(flag_show_inode, "Show inode ids", "inode", 'i'); args_parser.add_option(flag_show_inode, "Show inode ids", "inode", 'i');
args_parser.add_option(flag_show_raw_inode, "Show raw inode ids if possible", "raw-inode", 'I'); args_parser.add_option(flag_show_raw_inode, "Show raw inode ids if possible", "raw-inode", 'I');
@ -292,14 +302,14 @@ static size_t print_name(const struct stat& st, DeprecatedString const& name, Op
nprinted += printf(" -> ") + print_escaped(link_destination_or_error.value()); nprinted += printf(" -> ") + print_escaped(link_destination_or_error.value());
} }
} else { } else {
if (flag_classify) if (has_flag(flag_indicator_style, IndicatorStyle::SymbolicLink))
nprinted += printf("@"); nprinted += printf("@");
} }
} else if (S_ISDIR(st.st_mode)) { } else if (S_ISDIR(st.st_mode)) {
if (flag_classify) if (has_flag(flag_indicator_style, IndicatorStyle::Directory))
nprinted += printf("/"); nprinted += printf("/");
} else if (st.st_mode & 0111) { } else if (st.st_mode & 0111) {
if (flag_classify) if (has_flag(flag_indicator_style, IndicatorStyle::Executable))
nprinted += printf("*"); nprinted += printf("*");
} }