diff --git a/src/ls.c b/src/ls.c index e7d1d93..28be236 100644 --- a/src/ls.c +++ b/src/ls.c @@ -252,6 +252,7 @@ static bool print_color_indicator (const struct fileinfo *f, bool symlink_target); static void put_indicator (const struct bin_str *ind); static void add_ignore_pattern (const char *pattern); +static void do_not_ignore_filetype (const enum filetype f); static void attach (char *dest, const char *dirname, const char *name); static void clear_files (void); static void extract_dirs_from_files (char const *dirname, @@ -666,6 +667,9 @@ static struct ignore_pattern *ignore_patterns; variable itself to be ignored. */ static struct ignore_pattern *hide_patterns; +static bool ignore_filetypes; +static bool filetype_ignored[arg_directory + 1]; + /* True means output nongraphic chars in file names as '?'. (-q, --hide-control-chars) qmark_funny_chars and the quoting style (-Q, --quoting-style=WORD) are @@ -789,6 +793,7 @@ enum FULL_TIME_OPTION, GROUP_DIRECTORIES_FIRST_OPTION, HIDE_OPTION, + JUST_FILETYPE_OPTION, INDICATOR_STYLE_OPTION, QUOTING_STYLE_OPTION, SHOW_CONTROL_CHARS_OPTION, @@ -826,6 +831,7 @@ static struct option const long_options[] = DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION}, {"hide", required_argument, NULL, HIDE_OPTION}, {"ignore", required_argument, NULL, 'I'}, + {"just", required_argument, NULL, JUST_FILETYPE_OPTION}, {"indicator-style", required_argument, NULL, INDICATOR_STYLE_OPTION}, {"dereference", no_argument, NULL, 'L'}, {"literal", no_argument, NULL, 'N'}, @@ -894,6 +900,33 @@ static enum color_type const color_types[] = }; ARGMATCH_VERIFY (color_args, color_types); +static char const *const just_filetype_args[] = +{ + "f", "fifos", + "c", "character-devices", + "d", "directories", + "b", "block-devices", + "n", "normal", + "l", "symbolic-links", + "s", "sockets", + "w", "whiteouts", + "a", "arg-directories", + NULL +}; +static enum filetype const just_filetype_types[] = +{ + fifo, fifo, + chardev, chardev, + directory, directory, + blockdev, blockdev, + normal, normal, + symbolic_link, symbolic_link, + sock, sock, + whiteout, whiteout, + arg_directory, arg_directory +}; +ARGMATCH_VERIFY (just_filetype_args, just_filetype_types); + /* Information about filling a column. */ struct column_info { @@ -1640,6 +1673,14 @@ decode_switches (int argc, char **argv) } } } + { + ignore_filetypes = false; + int i; + for (i = 0; i != arg_directory + 1; ++i) + { + filetype_ignored[i] = true; + } + } while (true) { @@ -1865,6 +1906,15 @@ decode_switches (int argc, char **argv) } break; + case JUST_FILETYPE_OPTION: + { + enum filetype just_filetype = XARGMATCH ("--just", optarg, + just_filetype_args, + just_filetype_types); + do_not_ignore_filetype(just_filetype); + } + break; + case SORT_OPTION: sort_type = XARGMATCH ("--sort", optarg, sort_args, sort_types); sort_type_specified = true; @@ -2503,6 +2553,23 @@ queue_directory (char const *name, char const *realname, bool command_line_arg) pending_dirs = new; } +/* set this filetype to be paid attention to */ +static void +do_not_ignore_filetype(const enum filetype ftype) +{ + ignore_filetypes = true; + filetype_ignored[ftype] = false; +} + +/* Return true if this filetype should be ignored. */ +static bool +is_filetype_ignored(enum filetype ftype) +{ + return ignore_filetypes && filetype_ignored[ftype]; +} + + + /* Read directory NAME, and list the files in it. If REALNAME is nonzero, print its name instead of NAME; this is used for symbolic links to directories. @@ -2598,6 +2665,10 @@ print_dir (char const *name, char const *realname, bool command_line_arg) case DT_WHT: type = whiteout; break; # endif } + if (is_filetype_ignored(type)) + { + continue; + } #endif total_blocks += gobble_file (next->d_name, type, RELIABLE_D_INO (next), @@ -4816,6 +4887,11 @@ Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.\n\ -i, --inode print the index number of each file\n\ -I, --ignore=PATTERN do not list implied entries matching shell PATTERN\ \n\ + --just=FILETYPE only list implied entries of FILETYPE, filetyes:\n\ + arg-directories block-devices character-devices\n\ + directories fifos normal symbolic-links sockets\n\ + whiteouts\n\ +\n\ -k, --kibibytes default to 1024-byte blocks for disk usage\n\ "), stdout); fputs (_("\