]> Sergey Matveev's repositories - nnn.git/commitdiff
Option to disable dir auto-select
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 21 Oct 2018 18:00:46 +0000 (23:30 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 21 Oct 2018 18:00:46 +0000 (23:30 +0530)
README.md
nnn.1
nnn.c

index 82cc2170b85e72073d55a29c1f20acfdde1ca774..3f2aa44a306d3da4b3c5a2bb50289ea4e30fc6b6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -278,7 +278,9 @@ If `nnn` is invoked as root or the environment variable `NNN_SHOW_HIDDEN` is set
 
 In this mode directories are opened in filter mode, allowing continuous navigation. Works best with the **arrow keys**.
 
-In case of only one match and it's a directory, `nnn` auto selects the directory and enters it in this mode.
+In case of only one match and it's a directory, `nnn` auto selects the directory and enters it in this mode. To disable this behaviour,
+
+    export NNN_NO_AUTOSELECT=1
 
 #### File indicators
 
diff --git a/nnn.1 b/nnn.1
index c99c686e3553904a711b38c3a607653747fd1136..99b2bdbba9bf291d432cd5afb930b44259dca03e 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -282,6 +282,11 @@ for filenames having quote(s) in them.
 .Bd -literal
     export NNN_SHOW_HIDDEN=1
 .Ed
+.Pp
+\fBNNN_NO_AUTOSELECT:\fR Disable directory auto-selection in \fInavigate-as-you-type\fR mode.
+.Bd -literal
+    export export NNN_NO_AUTOSELECT=1
+.Ed
 .Sh KNOWN ISSUES
 If you are using urxvt you might have to set backspace key to DEC.
 .Sh AUTHORS
diff --git a/nnn.c b/nnn.c
index 2a59535c18f26e5b1f7fac88241025f4f56cfe10..76f11bb9f192e4f30561f66cfd61b2e70f2c8fbf 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -241,26 +241,28 @@ typedef struct {
 
 /* Settings */
 typedef struct {
-       ushort filtermode : 1;  /* Set to enter filter mode */
-       ushort mtimeorder : 1;  /* Set to sort by time modified */
-       ushort sizeorder  : 1;  /* Set to sort by file size */
-       ushort apparentsz : 1;  /* Set to sort by apparent size (disk usage) */
-       ushort blkorder   : 1;  /* Set to sort by blocks used (disk usage) */
-       ushort showhidden : 1;  /* Set to show hidden files */
-       ushort copymode   : 1;  /* Set when copying files */
-       ushort showdetail : 1;  /* Clear to show fewer file info */
-       ushort showcolor  : 1;  /* Set to show dirs in blue */
-       ushort dircolor   : 1;  /* Current status of dir color */
-       ushort metaviewer : 1;  /* Index of metadata viewer in utils[] */
-       ushort quote      : 1;  /* Copy paths within quotes */
-       ushort noxdisplay : 1;  /* X11 is not available */
-       ushort color      : 3;  /* Color code for directories */
+       uint filtermode : 1;  /* Set to enter filter mode */
+       uint mtimeorder : 1;  /* Set to sort by time modified */
+       uint sizeorder  : 1;  /* Set to sort by file size */
+       uint apparentsz : 1;  /* Set to sort by apparent size (disk usage) */
+       uint blkorder   : 1;  /* Set to sort by blocks used (disk usage) */
+       uint showhidden : 1;  /* Set to show hidden files */
+       uint copymode   : 1;  /* Set when copying files */
+       uint autoselect : 1;  /* Auto-select dir in nav-as-you-type mode */
+       uint showdetail : 1;  /* Clear to show fewer file info */
+       uint showcolor  : 1;  /* Set to show dirs in blue */
+       uint dircolor   : 1;  /* Current status of dir color */
+       uint metaviewer : 1;  /* Index of metadata viewer in utils[] */
+       uint quote      : 1;  /* Copy paths within quotes */
+       uint noxdisplay : 1;  /* X11 is not available */
+       uint color      : 3;  /* Color code for directories */
+       uint reserved   : 15;
 } settings;
 
 /* GLOBALS */
 
 /* Configuration */
-static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 4};
+static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 4, 0};
 
 static struct entry *dents;
 static char *pnamebuf, *pcopybuf;
@@ -1159,7 +1161,7 @@ filterentries(char *path)
                                        continue;
 
                                /* If the only match is a dir, auto-select and cd into it */
-                               if (cfg.filtermode && ndents == 1 && S_ISDIR(dents[0].mode)) {
+                               if (ndents == 1 && cfg.filtermode && cfg.autoselect && S_ISDIR(dents[0].mode)) {
                                        *ch = KEY_ENTER;
                                        cur = 0;
                                        goto end;
@@ -3500,12 +3502,16 @@ main(int argc, char *argv[])
                g_tmpfplen = xstrlcpy(g_tmpfpath, "/tmp", MAX_HOME_LEN);
 
        /* Check if X11 is available */
-       if (g_tmpfplen && getenv("NNN_NO_X")) {
+       if (!copier && g_tmpfplen && getenv("NNN_NO_X")) {
                cfg.noxdisplay = 1;
                xstrlcpy(g_cppath, g_tmpfpath, MAX_HOME_LEN);
                xstrlcpy(g_cppath + g_tmpfplen - 1, "/.nnncp", MAX_HOME_LEN - g_tmpfplen);
        }
 
+       /* Disable auto-select if opted */
+       if (getenv("NNN_NO_AUTOSELECT"))
+               cfg.autoselect = 0;
+
        signal(SIGINT, SIG_IGN);
 
        /* Test initial path */