Wild mode for nav-as-you-type

This commit is contained in:
Arun Prakash Jana 2019-02-27 21:03:14 +05:30
parent 26861532a2
commit 3e053e9412
No known key found for this signature in database
GPG key ID: A75979F35C080412
7 changed files with 49 additions and 15 deletions

View file

@ -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] 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. The missing terminal file manager for X.
@ -228,11 +228,10 @@ optional args:
-s string filters [default: regex] -s string filters [default: regex]
-S du mode -S du mode
-v show version -v show version
-w wild mode
-h show help -h show help
``` ```
`>` indicates the currently selected entry in `nnn`.
#### Keyboard shortcuts #### Keyboard shortcuts
Press <kbd>?</kbd> in `nnn` to see the list anytime. 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 e Edit in EDITOR p Open in PAGER
ORDER TOGGLES ORDER TOGGLES
^J Disk usage S Apparent du ^J Disk usage S Apparent du
t Time modified s Size ^W Random s Size t Time modified
MISC MISC
! ^] Spawn SHELL C Execute entry ! ^] Spawn SHELL C Execute entry
R ^V Run/pick script L Lock terminal 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 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 #### File indicators
The following indicators are used in the detail view: The following indicators are used in the detail view:

8
nnn.1
View file

@ -16,6 +16,7 @@
.Op Ar -s .Op Ar -s
.Op Ar -S .Op Ar -S
.Op Ar -v .Op Ar -v
.Op Ar -w
.Op Ar -h .Op Ar -h
.Op Ar PATH .Op Ar PATH
.Sh DESCRIPTION .Sh DESCRIPTION
@ -135,6 +136,8 @@ ORDER TOGGLES
Toggle disk usage analyzer mode Toggle disk usage analyzer mode
.It Ic S .It Ic S
Toggle sort by apparent size Toggle sort by apparent size
.It Ic ^W
Wild mode
.It Ic t .It Ic t
Toggle sort by time modified Toggle sort by time modified
.It Ic s .It Ic s
@ -198,6 +201,9 @@ supports the following options:
.Fl v .Fl v
show version and exit show version and exit
.Pp .Pp
.Fl w
wild mode - entries unsorted on directory load
.Pp
.Fl h .Fl h
show program help and exit show program help and exit
.Sh CONFIGURATION .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. allowing continuous navigation. Works best with the \fBarrow keys\fR.
.br .br
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.
.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 .Sh SELECTION MODE
The absolute path of a single file can be copied to clipboard by pressing \fI^K\fR if 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). NNN_COPIER is set (see ENVIRONMENT section below).

View file

@ -22,6 +22,7 @@ _nnn () {
-s -s
-S -S
-v -v
-w
) )
opts_with_arg=( opts_with_arg=(
-b -b

View 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 'use substring match for filters'
complete -c nnn -s S -d 'start in disk usage analyzer mode' 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 v -d 'show program version and exit'
complete -c nnn -s w -d 'wild mode'

View file

@ -20,6 +20,7 @@ args=(
'(-s)-s[use substring match for filters]' '(-s)-s[use substring match for filters]'
'(-S)-S[start in disk usage analyzer mode]' '(-S)-S[start in disk usage analyzer mode]'
'(-v)-v[show program version and exit]' '(-v)-v[show program version and exit]'
'(-w)-w[wild mode]'
'*:filename:_files' '*:filename:_files'
) )
_arguments -S -s $args _arguments -S -s $args

View file

@ -285,7 +285,7 @@ typedef struct {
uint dircolor : 1; /* Current status of dir color */ uint dircolor : 1; /* Current status of dir color */
uint metaviewer : 1; /* Index of metadata viewer in utils[] */ uint metaviewer : 1; /* Index of metadata viewer in utils[] */
uint ctxactive : 1; /* Context active or not */ uint ctxactive : 1; /* Context active or not */
uint reserved : 8; uint reserved : 7;
/* The following settings are global */ /* The following settings are global */
uint curctx : 2; /* Current context number */ uint curctx : 2; /* Current context number */
uint picker : 1; /* Write selection to user-specified file */ 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 runctx : 2; /* The context in which script is to be run */
uint restrict0b : 1; /* Restrict 0-byte file opening */ uint restrict0b : 1; /* Restrict 0-byte file opening */
uint filter_re : 1; /* Use regex filters */ uint filter_re : 1; /* Use regex filters */
uint wild : 1; /* Do not sort entries on dir load */
} settings; } settings;
/* Contexts or workspaces */ /* Contexts or workspaces */
@ -311,7 +312,7 @@ typedef struct {
/* GLOBALS */ /* GLOBALS */
/* Configuration, contexts */ /* 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 context g_ctx[CTX_MAX] __attribute__ ((aligned));
static struct entry *dents; static struct entry *dents;
@ -2443,7 +2444,7 @@ static bool show_help(char *path)
"ce Edit in EDITOR p Open in PAGER\n" "ce Edit in EDITOR p Open in PAGER\n"
"1ORDER TOGGLES\n" "1ORDER TOGGLES\n"
"b^J Disk usage S Apparent du\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" "1MISC\n"
"9! ^] Spawn SHELL C Execute entry\n" "9! ^] Spawn SHELL C Execute entry\n"
"9R ^V Run/pick script L Lock terminal\n" "9R ^V Run/pick script L Lock terminal\n"
@ -2727,7 +2728,8 @@ static void populate(char *path, char *lastname)
if (!ndents) if (!ndents)
return; return;
qsort(dents, ndents, sizeof(*dents), entrycmp); if (!cfg.wild)
qsort(dents, ndents, sizeof(*dents), entrycmp);
#ifdef DBGMODE #ifdef DBGMODE
clock_gettime(CLOCK_REALTIME, &ts2); clock_gettime(CLOCK_REALTIME, &ts2);
@ -2834,7 +2836,7 @@ static void redraw(char *path)
else else
ncols -= 5; ncols -= 5;
if (cfg.showcolor) { if (!cfg.wild && cfg.showcolor) {
attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
cfg.dircolor = 1; cfg.dircolor = 1;
} }
@ -3301,6 +3303,7 @@ nochange:
} }
#endif #endif
presel = filterentries(path); presel = filterentries(path);
/* Save current */ /* Save current */
if (ndents) if (ndents)
copycurname(); copycurname();
@ -3311,7 +3314,8 @@ nochange:
case SEL_FSIZE: // fallthrough case SEL_FSIZE: // fallthrough
case SEL_ASIZE: // fallthrough case SEL_ASIZE: // fallthrough
case SEL_BSIZE: // fallthrough case SEL_BSIZE: // fallthrough
case SEL_MTIME: case SEL_MTIME: // fallthrough
case SEL_WILD:
switch (sel) { switch (sel) {
case SEL_MFLTR: case SEL_MFLTR:
cfg.filtermode ^= 1; cfg.filtermode ^= 1;
@ -3336,6 +3340,7 @@ nochange:
cfg.apparentsz = 0; cfg.apparentsz = 0;
cfg.blkorder = 0; cfg.blkorder = 0;
cfg.copymode = 0; cfg.copymode = 0;
cfg.wild = 0;
break; break;
case SEL_ASIZE: case SEL_ASIZE:
cfg.apparentsz ^= 1; cfg.apparentsz ^= 1;
@ -3344,8 +3349,7 @@ nochange:
cfg.blkorder = 1; cfg.blkorder = 1;
BLK_SHIFT = 0; BLK_SHIFT = 0;
} else } else
cfg.blkorder = 0; cfg.blkorder = 0; // fallthrough
break;
case SEL_BSIZE: case SEL_BSIZE:
if (sel == SEL_BSIZE) { if (sel == SEL_BSIZE) {
if (!cfg.apparentsz) if (!cfg.apparentsz)
@ -3362,14 +3366,25 @@ nochange:
cfg.mtimeorder = 0; cfg.mtimeorder = 0;
cfg.sizeorder = 0; cfg.sizeorder = 0;
cfg.copymode = 0; cfg.copymode = 0;
cfg.wild = 0;
break; break;
default: /* SEL_MTIME */ case SEL_MTIME:
cfg.mtimeorder ^= 1; cfg.mtimeorder ^= 1;
cfg.sizeorder = 0; cfg.sizeorder = 0;
cfg.apparentsz = 0; cfg.apparentsz = 0;
cfg.blkorder = 0; cfg.blkorder = 0;
cfg.copymode = 0; cfg.copymode = 0;
cfg.wild = 0;
break; 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 */ /* Save current */
@ -4013,7 +4028,7 @@ static void usage(void)
{ {
fprintf(stdout, fprintf(stdout,
"%s: nnn [-b key] [-C] [-e] [-i] [-l] [-n]\n" "%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" "The missing terminal file manager for X.\n\n"
"positional args:\n" "positional args:\n"
" PATH start dir [default: current dir]\n\n" " PATH start dir [default: current dir]\n\n"
@ -4028,6 +4043,7 @@ static void usage(void)
" -s string filters [default: regex]\n" " -s string filters [default: regex]\n"
" -S du mode\n" " -S du mode\n"
" -v show version\n" " -v show version\n"
" -w wild mode\n"
" -h show help\n\n" " -h show help\n\n"
"v%s\n%s\n", __func__, VERSION, GENERAL_INFO); "v%s\n%s\n", __func__, VERSION, GENERAL_INFO);
} }
@ -4038,7 +4054,7 @@ int main(int argc, char *argv[])
char *ipath = NULL; char *ipath = NULL;
int opt; int opt;
while ((opt = getopt(argc, argv, "Slib:Cenp:svh")) != -1) { while ((opt = getopt(argc, argv, "Slib:Cenp:svwh")) != -1) {
switch (opt) { switch (opt) {
case 'S': case 'S':
cfg.blkorder = 1; cfg.blkorder = 1;
@ -4084,6 +4100,9 @@ int main(int argc, char *argv[])
case 'v': case 'v':
fprintf(stdout, "%s\n", VERSION); fprintf(stdout, "%s\n", VERSION);
return 0; return 0;
case 'w':
cfg.wild = 1;
break;
case 'h': case 'h':
usage(); usage();
return 0; return 0;

View file

@ -70,6 +70,7 @@ enum action {
SEL_ASIZE, /* apparent size */ SEL_ASIZE, /* apparent size */
SEL_BSIZE, /* block size */ SEL_BSIZE, /* block size */
SEL_MTIME, SEL_MTIME,
SEL_WILD,
SEL_REDRAW, SEL_REDRAW,
SEL_COPY, SEL_COPY,
SEL_COPYMUL, SEL_COPYMUL,
@ -183,6 +184,8 @@ static struct key bindings[] = {
{ CONTROL('J'), SEL_BSIZE }, { CONTROL('J'), SEL_BSIZE },
/* Toggle sort by time */ /* Toggle sort by time */
{ 't', SEL_MTIME }, { 't', SEL_MTIME },
/* Wild mode */
{ CONTROL('W'), SEL_WILD },
/* Redraw window */ /* Redraw window */
{ CONTROL('L'), SEL_REDRAW }, { CONTROL('L'), SEL_REDRAW },
/* Copy currently selected file path */ /* Copy currently selected file path */