Option to disable dir auto-select

This commit is contained in:
Arun Prakash Jana 2018-10-21 23:30:46 +05:30
parent 7c9068627c
commit e454078571
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 31 additions and 18 deletions

View file

@ -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

5
nnn.1
View file

@ -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

40
nnn.c
View file

@ -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 */