]> Sergey Matveev's repositories - nnn.git/commitdiff
Show directories first
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 1 Apr 2017 20:18:33 +0000 (01:48 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 1 Apr 2017 20:18:33 +0000 (01:48 +0530)
README.md
nnn.c

index 5fa00f73b4b3e6dd368f9aefaf3bb0a1157bd194..0d9b83499e045b52e4b0828cdb613690067de07a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -54,11 +54,12 @@ I chose to fork because:
     - current item in reverse video
     - number of items in current directory
     - full name of currently selected file
+  - Directories first
+  - Sort numeric names in numeric order
   - Case-insensitive alphabetic content listing instead of upper case first
   - Roll over at the first and last entries of a directory (with Up/Down keys)
   - Removed navigation restriction with relative paths (and let permissions handle it)
   - Sort entries by file size (largest to smallest)
-  - Sort numeric names in numeric order
   - Shortcut to invoke file name copier (set using environment variable `NNN_COPIER`)
 - File associations
   - Environment variable `NNN_OPENER` to let desktop opener handle it all. E.g.:
diff --git a/nnn.c b/nnn.c
index 2939dac25b3a1d8a2fa678453e543eb44f78303b..802030e9976da5b32cc23d6fc4dd440f8dceaa11 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -395,13 +395,25 @@ visible(regex_t *regex, char *file)
 static int
 entrycmp(const void *va, const void *vb)
 {
+       static pEntry pa, pb;
+
+       pa = (pEntry)va;
+       pb = (pEntry)vb;
+
+       /* Sort directories first */
+       if (S_ISDIR(pb->mode) && !S_ISDIR(pa->mode))
+               return 1;
+       else if (S_ISDIR(pa->mode) && !S_ISDIR(pb->mode))
+               return -1;
+
+       /* Do the actual sorting */
        if (mtimeorder)
-               return ((pEntry)vb)->t - ((pEntry)va)->t;
+               return pb->t - pa->t;
 
        if (sizeorder)
-               return ((pEntry)vb)->size - ((pEntry)va)->size;
+               return pb->size - pa->size;
 
-       return xstricmp(((pEntry)va)->name, ((pEntry)vb)->name);
+       return xstricmp(pa->name, pb->name);
 }
 
 static void