From e454078571f3a995cf1d8310b068a47d51a840d0 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 21 Oct 2018 23:30:46 +0530 Subject: [PATCH] Option to disable dir auto-select --- README.md | 4 +++- nnn.1 | 5 +++++ nnn.c | 40 +++++++++++++++++++++++----------------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 82cc217..3f2aa44 100644 --- 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 c99c686..99b2bdb 100644 --- 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 2a59535..76f11bb 100644 --- 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 */