]> Sergey Matveev's repositories - nnn.git/commitdiff
Wild mode for nav-as-you-type
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 27 Feb 2019 15:33:14 +0000 (21:03 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 28 Feb 2019 17:06:54 +0000 (22:36 +0530)
README.md
nnn.1
scripts/auto-completion/bash/nnn-completion.bash
scripts/auto-completion/fish/nnn.fish
scripts/auto-completion/zsh/_nnn
src/nnn.c
src/nnn.h

index 215058e4fa89d177acdf220f731166b3071885de..1623e6fc500cfb6b1f592ffe2638f4ca611cfae7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -210,7 +210,7 @@ Search keyword and option completion scripts for Bash, Fish and Zsh can be found
 
 ```
 usage: nnn [-b key] [-C] [-e] [-i] [-l] [-n]
-           [-p file] [-s] [-S] [-v] [-h] [PATH]
+           [-p file] [-s] [-S] [-v] [-w] [-h] [PATH]
 
 The missing terminal file manager for X.
 
@@ -228,11 +228,10 @@ optional args:
  -s      string filters [default: regex]
  -S      du mode
  -v      show version
+ -w      wild mode
  -h      show help
 ```
 
-`>` indicates the currently selected entry in `nnn`.
-
 #### Keyboard shortcuts
 
 Press <kbd>?</kbd> in `nnn` to see the list anytime.
@@ -264,7 +263,7 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
             e  Edit in EDITOR    p  Open in PAGER
  ORDER TOGGLES
            ^J  Disk usage        S  Apparent du
-            t  Time modified     s  Size
+           ^W  Random  s  Size   t  Time modified
  MISC
          ! ^]  Spawn SHELL       C  Execute entry
          R ^V  Run/pick script   L  Lock terminal
@@ -355,6 +354,8 @@ In case of only one match and it's a directory, `nnn` auto selects the directory
 
     export NNN_NO_AUTOSELECT=1
 
+The _wild mode_ program option can be handy for users who use this mode constantly. The entries are unsorted when the directory loads. Applying filters sort the entries (with directories on top). Directory color is disabled in this mode.
+
 #### File indicators
 
 The following indicators are used in the detail view:
diff --git a/nnn.1 b/nnn.1
index 1a42db475b4ec00182a79029dc807d4622964259..73ec86ea519bfc1fd149ba243c932a4e529dddb1 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -16,6 +16,7 @@
 .Op Ar -s
 .Op Ar -S
 .Op Ar -v
+.Op Ar -w
 .Op Ar -h
 .Op Ar PATH
 .Sh DESCRIPTION
@@ -135,6 +136,8 @@ ORDER TOGGLES
 Toggle disk usage analyzer mode
 .It Ic S
 Toggle sort by apparent size
+.It Ic ^W
+Wild mode
 .It Ic t
 Toggle sort by time modified
 .It Ic s
@@ -198,6 +201,9 @@ supports the following options:
 .Fl v
         show version and exit
 .Pp
+.Fl w
+        wild mode - entries unsorted on directory load
+.Pp
 .Fl h
         show program help and exit
 .Sh CONFIGURATION
@@ -250,6 +256,8 @@ In the \fInavigate-as-you-type\fR mode directories are opened in filter mode,
 allowing continuous navigation. Works best with the \fBarrow keys\fR.
 .br
 In case of only one match and it's a directory, `nnn` auto selects the directory and enters it in this mode.
+.br
+The \fIwild mode\fR can be handy for users who use the \fInavigate-as-you-type\fR mode constantly. The entries are unsorted when the directory loads. Applying filters sort the entries (with directories on top). Directory color is disabled in this mode.
 .Sh SELECTION MODE
 The absolute path of a single file can be copied to clipboard by pressing \fI^K\fR if
 NNN_COPIER is set (see ENVIRONMENT section below).
index 095adb99fb92e52efd4df0c0ce3b5fc84c90c075..7a265bc3c7c8e86a759dc7fb019f027d3de6a512 100644 (file)
@@ -22,6 +22,7 @@ _nnn () {
         -s
         -S
         -v
+        -w
     )
     opts_with_arg=(
         -b
index 3ec36eb5852440f51824ff0c39b661b54289a889..f6e86a4352d2e681ae91f6c6abab378d1e433840 100644 (file)
@@ -16,3 +16,4 @@ complete -c nnn -s p -r -d 'copy selection to file'
 complete -c nnn -s s    -d 'use substring match for filters'
 complete -c nnn -s S    -d 'start in disk usage analyzer mode'
 complete -c nnn -s v    -d 'show program version and exit'
+complete -c nnn -s w    -d 'wild mode'
index 9171a913e029f5229d587fa985b2adef2af13bb8..0ec803346450f1301caa1b3b41e4b714edc57619 100644 (file)
@@ -20,6 +20,7 @@ args=(
     '(-s)-s[use substring match for filters]'
     '(-S)-S[start in disk usage analyzer mode]'
     '(-v)-v[show program version and exit]'
+    '(-w)-w[wild mode]'
     '*:filename:_files'
 )
 _arguments -S -s $args
index cbad15e325d0aa30e4f0e3cab01bba21cb7c35de..14f72e1057334d49cc7cf238c25bcffc00c076aa 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -285,7 +285,7 @@ typedef struct {
        uint dircolor   : 1;  /* Current status of dir color */
        uint metaviewer : 1;  /* Index of metadata viewer in utils[] */
        uint ctxactive  : 1;  /* Context active or not */
-       uint reserved   : 8;
+       uint reserved   : 7;
        /* The following settings are global */
        uint curctx     : 2;  /* Current context number */
        uint picker     : 1;  /* Write selection to user-specified file */
@@ -296,6 +296,7 @@ typedef struct {
        uint runctx     : 2;  /* The context in which script is to be run */
        uint restrict0b : 1;  /* Restrict 0-byte file opening */
        uint filter_re  : 1;  /* Use regex filters */
+       uint wild       : 1;  /* Do not sort entries on dir load */
 } settings;
 
 /* Contexts or workspaces */
@@ -311,7 +312,7 @@ typedef struct {
 /* GLOBALS */
 
 /* Configuration, contexts */
-static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0};
 static context g_ctx[CTX_MAX] __attribute__ ((aligned));
 
 static struct entry *dents;
@@ -2443,7 +2444,7 @@ static bool show_help(char *path)
                  "ce  Edit in EDITOR    p  Open in PAGER\n"
                "1ORDER TOGGLES\n"
                 "b^J  Disk usage        S  Apparent du\n"
-                 "ct  Time modified     s  Size\n"
+                "b^W  Random  s  Size   t  Time modified\n"
                "1MISC\n"
               "9! ^]  Spawn SHELL       C  Execute entry\n"
               "9R ^V  Run/pick script   L  Lock terminal\n"
@@ -2727,7 +2728,8 @@ static void populate(char *path, char *lastname)
        if (!ndents)
                return;
 
-       qsort(dents, ndents, sizeof(*dents), entrycmp);
+       if (!cfg.wild)
+               qsort(dents, ndents, sizeof(*dents), entrycmp);
 
 #ifdef DBGMODE
        clock_gettime(CLOCK_REALTIME, &ts2);
@@ -2834,7 +2836,7 @@ static void redraw(char *path)
        else
                ncols -= 5;
 
-       if (cfg.showcolor) {
+       if (!cfg.wild && cfg.showcolor) {
                attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
                cfg.dircolor = 1;
        }
@@ -3301,6 +3303,7 @@ nochange:
                        }
 #endif
                        presel = filterentries(path);
+
                        /* Save current */
                        if (ndents)
                                copycurname();
@@ -3311,7 +3314,8 @@ nochange:
                case SEL_FSIZE: // fallthrough
                case SEL_ASIZE: // fallthrough
                case SEL_BSIZE: // fallthrough
-               case SEL_MTIME:
+               case SEL_MTIME: // fallthrough
+               case SEL_WILD:
                        switch (sel) {
                        case SEL_MFLTR:
                                cfg.filtermode ^= 1;
@@ -3336,6 +3340,7 @@ nochange:
                                cfg.apparentsz = 0;
                                cfg.blkorder = 0;
                                cfg.copymode = 0;
+                               cfg.wild = 0;
                                break;
                        case SEL_ASIZE:
                                cfg.apparentsz ^= 1;
@@ -3344,8 +3349,7 @@ nochange:
                                        cfg.blkorder = 1;
                                        BLK_SHIFT = 0;
                                } else
-                                       cfg.blkorder = 0;
-                               break;
+                                       cfg.blkorder = 0; // fallthrough
                        case SEL_BSIZE:
                                if (sel == SEL_BSIZE) {
                                        if (!cfg.apparentsz)
@@ -3362,14 +3366,25 @@ nochange:
                                cfg.mtimeorder = 0;
                                cfg.sizeorder = 0;
                                cfg.copymode = 0;
+                               cfg.wild = 0;
                                break;
-                       default: /* SEL_MTIME */
+                       case SEL_MTIME:
                                cfg.mtimeorder ^= 1;
                                cfg.sizeorder = 0;
                                cfg.apparentsz = 0;
                                cfg.blkorder = 0;
                                cfg.copymode = 0;
+                               cfg.wild = 0;
                                break;
+                       default: /* SEL_WILD */
+                               cfg.wild ^= 1;
+                               cfg.mtimeorder = 0;
+                               cfg.sizeorder = 0;
+                               cfg.apparentsz = 0;
+                               cfg.blkorder = 0;
+                               cfg.copymode = 0;
+                               setdirwatch();
+                               goto nochange;
                        }
 
                        /* Save current */
@@ -4013,7 +4028,7 @@ static void usage(void)
 {
        fprintf(stdout,
                "%s: nnn [-b key] [-C] [-e] [-i] [-l] [-n]\n"
-               "           [-p file] [-s] [-S] [-v] [-h] [PATH]\n\n"
+               "           [-p file] [-s] [-S] [-v] [-w] [-h] [PATH]\n\n"
                "The missing terminal file manager for X.\n\n"
                "positional args:\n"
                "  PATH   start dir [default: current dir]\n\n"
@@ -4028,6 +4043,7 @@ static void usage(void)
                " -s      string filters [default: regex]\n"
                " -S      du mode\n"
                " -v      show version\n"
+               " -w      wild mode\n"
                " -h      show help\n\n"
                "v%s\n%s\n", __func__, VERSION, GENERAL_INFO);
 }
@@ -4038,7 +4054,7 @@ int main(int argc, char *argv[])
        char *ipath = NULL;
        int opt;
 
-       while ((opt = getopt(argc, argv, "Slib:Cenp:svh")) != -1) {
+       while ((opt = getopt(argc, argv, "Slib:Cenp:svwh")) != -1) {
                switch (opt) {
                case 'S':
                        cfg.blkorder = 1;
@@ -4084,6 +4100,9 @@ int main(int argc, char *argv[])
                case 'v':
                        fprintf(stdout, "%s\n", VERSION);
                        return 0;
+               case 'w':
+                       cfg.wild = 1;
+                       break;
                case 'h':
                        usage();
                        return 0;
index a588a33fed343ff25ca634427ec31e748300a4b9..a2a858bfe97e64e425de6a64ffa69ecc7f0faca0 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -70,6 +70,7 @@ enum action {
        SEL_ASIZE,  /* apparent size */
        SEL_BSIZE,  /* block size */
        SEL_MTIME,
+       SEL_WILD,
        SEL_REDRAW,
        SEL_COPY,
        SEL_COPYMUL,
@@ -183,6 +184,8 @@ static struct key bindings[] = {
        { CONTROL('J'),   SEL_BSIZE },
        /* Toggle sort by time */
        { 't',            SEL_MTIME },
+       /* Wild mode */
+       { CONTROL('W'),   SEL_WILD },
        /* Redraw window */
        { CONTROL('L'),   SEL_REDRAW },
        /* Copy currently selected file path */