aboutsummaryrefslogtreecommitdiffstats
path: root/nnn.c
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-02 01:48:33 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-02 01:48:33 +0530
commit951d32361699ede7d42f06f72cd3b3813a0be71c (patch)
tree07b879fe7affe30cfaba0a6d3002186a713ca7ca /nnn.c
parent0e82544199866ce217a2a6e8dd50f553fa5cc582 (diff)
downloadnnn-951d32361699ede7d42f06f72cd3b3813a0be71c.tar.gz
Show directories first
Diffstat (limited to 'nnn.c')
-rw-r--r--nnn.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/nnn.c b/nnn.c
index 2939dac..802030e 100644
--- 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