]> Sergey Matveev's repositories - nnn.git/commitdiff
Add 't' command to sort output by entry's mtime
authorsin <sin@2f30.org>
Sat, 31 Jan 2015 22:02:59 +0000 (22:02 +0000)
committersin <sin@2f30.org>
Sat, 31 Jan 2015 22:02:59 +0000 (22:02 +0000)
config.def.h
noice.1
noice.c

index 996436f321be4cffe4fe82201d06629c1e05facb..3b12199e8df63de36e429b8516febc994b53b779 100644 (file)
@@ -47,4 +47,5 @@ struct key bindings[] = {
        { '!',            SEL_SH },
        /* Change dir */
        { 'c',            SEL_CD },
+       { 't',            SEL_MTIME },
 };
diff --git a/noice.1 b/noice.1
index 61669e5ffc1af6e8b4eacfd15d711b6dbec63007..d3d087908b3d8ab51ecf1b33be17683ad5eeafcb 100644 (file)
--- a/noice.1
+++ b/noice.1
@@ -47,6 +47,8 @@ Change filter (see below for more information).
 Enter filter-as-you-type mode.
 .It Ic c
 Change into the given directory.
+.It Ic t
+Sort by time modified.
 .It Ic !
 Spawn shell in current directory.
 .It Ic q
diff --git a/noice.c b/noice.c
index 5358111f98a9665f112bb4e1c38bd955bde18714..04115cf5aa50545dcc437bdc422f69f854927e0b 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -56,6 +56,7 @@ enum action {
        SEL_PGUP,
        SEL_SH,
        SEL_CD,
+       SEL_MTIME,
 };
 
 struct key {
@@ -68,8 +69,11 @@ struct key {
 struct entry {
        char *name;
        mode_t mode;
+       time_t t;
 };
 
+int mtimeorder;
+
 /*
  * Layout:
  * .---------
@@ -231,6 +235,8 @@ entrycmp(const void *va, const void *vb)
        a = (struct entry *)va;
        b = (struct entry *)vb;
 
+       if (mtimeorder)
+               return b->t - a->t;
        return strcmp(a->name, b->name);
 }
 
@@ -487,6 +493,7 @@ dentfill(char *path, struct entry **dents,
                if (r == -1)
                        printerr(1, "lstat");
                (*dents)[n].mode = sb.st_mode;
+               (*dents)[n].t = sb.st_mtime;
                n++;
        }
 
@@ -809,6 +816,9 @@ moretyping:
                        filter = xstrdup(ifilter); /* Reset filter */
                        DPRINTF_S(path);
                        goto out;
+               case SEL_MTIME:
+                       mtimeorder = !mtimeorder;
+                       goto out;
                }
        }