Browse Source

ls: Only append file type indicators when -F or --classify is specified

Andreas Kling 4 years ago
parent
commit
b413c7ae6a
2 changed files with 9 additions and 3 deletions
  1. 1 0
      Base/usr/share/man/man1/ls.md
  2. 8 3
      Userland/ls.cpp

+ 1 - 0
Base/usr/share/man/man1/ls.md

@@ -20,6 +20,7 @@ If no *path* argument is provided the current working directory is used.
 * `-a`, `--all`: Show dotfiles
 * `-a`, `--all`: Show dotfiles
 * `-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
 * `-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
 * `-t`: Sort files by timestamp

+ 8 - 3
Userland/ls.cpp

@@ -51,6 +51,7 @@
 static int do_file_system_object_long(const char* path);
 static int do_file_system_object_long(const char* path);
 static int do_file_system_object_short(const char* path);
 static int do_file_system_object_short(const char* path);
 
 
+static bool flag_classify = false;
 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;
@@ -107,6 +108,7 @@ int main(int argc, char** argv)
     args_parser.add_option(flag_long, "Display long info", "long", 'l');
     args_parser.add_option(flag_long, "Display long info", "long", 'l');
     args_parser.add_option(flag_sort_by_timestamp, "Sort files by timestamp", nullptr, 't');
     args_parser.add_option(flag_sort_by_timestamp, "Sort files by timestamp", nullptr, 't');
     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_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_print_numeric, "In long format, display numeric UID/GID", "numeric-uid-gid", 'n');
     args_parser.add_option(flag_print_numeric, "In long format, display numeric UID/GID", "numeric-uid-gid", 'n');
@@ -230,12 +232,15 @@ static size_t print_name(const struct stat& st, const String& name, const char*
                 nprinted += printf(" -> ") + print_escaped(link_destination.characters());
                 nprinted += printf(" -> ") + print_escaped(link_destination.characters());
             }
             }
         } else {
         } else {
-            nprinted += printf("@");
+            if (flag_classify)
+                nprinted += printf("@");
         }
         }
     } else if (S_ISDIR(st.st_mode)) {
     } else if (S_ISDIR(st.st_mode)) {
-        nprinted += printf("/");
+        if (flag_classify)
+            nprinted += printf("/");
     } else if (st.st_mode & 0111) {
     } else if (st.st_mode & 0111) {
-        nprinted += printf("*");
+        if (flag_classify)
+            nprinted += printf("*");
     }
     }
 
 
     if (!flag_disable_hyperlinks) {
     if (!flag_disable_hyperlinks) {