mirror of
https://github.com/jarun/nnn.git
synced 2024-12-01 02:49:44 +00:00
Run a command at filter prompt
This is a conveninece for nav-as-you-type mode. With this program option, on pressing ^P, the filter is executed as cmd.
This commit is contained in:
parent
ccf20f830b
commit
bb5ef221b3
|
@ -202,7 +202,7 @@ Option completion scripts for Bash, Fish and Zsh can be found in respective subd
|
||||||
#### Cmdline options
|
#### Cmdline options
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: nnn [-a] [-b key] [-d] [-H] [-i] [-n] [-o]
|
usage: nnn [-a] [-b key] [-d] [-f] [-H] [-i] [-n] [-o]
|
||||||
[-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]
|
[-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]
|
||||||
|
|
||||||
The missing terminal file manager for X.
|
The missing terminal file manager for X.
|
||||||
|
@ -214,6 +214,7 @@ optional args:
|
||||||
-a use access time
|
-a use access time
|
||||||
-b key open bookmark key
|
-b key open bookmark key
|
||||||
-d detail mode
|
-d detail mode
|
||||||
|
-f run filter as cmd on ^P
|
||||||
-H show hidden files
|
-H show hidden files
|
||||||
-i nav-as-you-type mode
|
-i nav-as-you-type mode
|
||||||
-n version sort
|
-n version sort
|
||||||
|
|
9
nnn.1
9
nnn.1
|
@ -9,6 +9,7 @@
|
||||||
.Op Ar -a
|
.Op Ar -a
|
||||||
.Op Ar -b key
|
.Op Ar -b key
|
||||||
.Op Ar -d
|
.Op Ar -d
|
||||||
|
.Op Ar -f
|
||||||
.Op Ar -H
|
.Op Ar -H
|
||||||
.Op Ar -i
|
.Op Ar -i
|
||||||
.Op Ar -n
|
.Op Ar -n
|
||||||
|
@ -46,6 +47,9 @@ supports the following options:
|
||||||
.Fl d
|
.Fl d
|
||||||
detail mode
|
detail mode
|
||||||
.Pp
|
.Pp
|
||||||
|
.Fl f
|
||||||
|
run filter as command when ^P is pressed
|
||||||
|
.Pp
|
||||||
.Fl H
|
.Fl H
|
||||||
show hidden files
|
show hidden files
|
||||||
.Pp
|
.Pp
|
||||||
|
@ -116,6 +120,8 @@ with a '^' (caret) symbol.
|
||||||
.Pp
|
.Pp
|
||||||
There is a program option to filter entries by substring match instead of regex.
|
There is a program option to filter entries by substring match instead of regex.
|
||||||
.Pp
|
.Pp
|
||||||
|
There is a program option to execute the current filter as a command when \fI^P\fR is pressed.
|
||||||
|
.Pp
|
||||||
In the \fInavigate-as-you-type\fR mode directories are opened in filter mode,
|
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
|
||||||
|
@ -157,8 +163,7 @@ when dealing with the !, e and p commands respectively. A single combination to
|
||||||
NOTE: To run a plugin directly, press 'x' followed by the plugin key.
|
NOTE: To run a plugin directly, press 'x' followed by the plugin key.
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_USE_EDITOR:\fR use VISUAL (else EDITOR, preferably CLI, fallback vi) to handle text
|
\fBNNN_USE_EDITOR:\fR use VISUAL (else EDITOR, preferably CLI, fallback vi) to handle text files.
|
||||||
files.
|
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
export NNN_USE_EDITOR=1
|
export NNN_USE_EDITOR=1
|
||||||
.Ed
|
.Ed
|
||||||
|
|
36
src/nnn.c
36
src/nnn.c
|
@ -217,7 +217,7 @@ typedef struct {
|
||||||
uint selmode : 1; /* Set when selecting files */
|
uint selmode : 1; /* Set when selecting files */
|
||||||
uint showdetail : 1; /* Clear to show fewer file info */
|
uint showdetail : 1; /* Clear to show fewer file info */
|
||||||
uint ctxactive : 1; /* Context active or not */
|
uint ctxactive : 1; /* Context active or not */
|
||||||
uint reserved : 7;
|
uint reserved : 6;
|
||||||
/* The following settings are global */
|
/* The following settings are global */
|
||||||
uint curctx : 2; /* Current context number */
|
uint curctx : 2; /* Current context number */
|
||||||
uint dircolor : 1; /* Current status of dir color */
|
uint dircolor : 1; /* Current status of dir color */
|
||||||
|
@ -230,6 +230,7 @@ typedef struct {
|
||||||
uint runplugin : 1; /* Choose plugin mode */
|
uint runplugin : 1; /* Choose plugin mode */
|
||||||
uint runctx : 2; /* The context in which plugin is to be run */
|
uint runctx : 2; /* The context in which plugin is to be run */
|
||||||
uint filter_re : 1; /* Use regex filters */
|
uint filter_re : 1; /* Use regex filters */
|
||||||
|
uint filtercmd : 1; /* Run filter as command on no match */
|
||||||
uint trash : 1; /* Move removed files to trash */
|
uint trash : 1; /* Move removed files to trash */
|
||||||
uint mtime : 1; /* Use modification time (else access time) */
|
uint mtime : 1; /* Use modification time (else access time) */
|
||||||
} settings;
|
} settings;
|
||||||
|
@ -270,6 +271,7 @@ static settings cfg = {
|
||||||
0, /* runplugin */
|
0, /* runplugin */
|
||||||
0, /* runctx */
|
0, /* runctx */
|
||||||
1, /* filter_re */
|
1, /* filter_re */
|
||||||
|
0, /* filtercmd */
|
||||||
0, /* trash */
|
0, /* trash */
|
||||||
1, /* mtime */
|
1, /* mtime */
|
||||||
};
|
};
|
||||||
|
@ -1644,12 +1646,10 @@ static int matches(const char *fltr)
|
||||||
ndents = fill(fltr, &re);
|
ndents = fill(fltr, &re);
|
||||||
if (cfg.filter_re)
|
if (cfg.filter_re)
|
||||||
regfree(&re);
|
regfree(&re);
|
||||||
if (!ndents)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
qsort(dents, ndents, sizeof(*dents), entrycmp);
|
qsort(dents, ndents, sizeof(*dents), entrycmp);
|
||||||
|
|
||||||
return 0;
|
return ndents;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filterentries(char *path)
|
static int filterentries(char *path)
|
||||||
|
@ -1728,23 +1728,21 @@ static int filterentries(char *path)
|
||||||
if (r == OK) {
|
if (r == OK) {
|
||||||
/* Handle all control chars in main loop */
|
/* Handle all control chars in main loop */
|
||||||
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^' && *ch != '^') {
|
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^' && *ch != '^') {
|
||||||
|
DPRINTF_D(*ch);
|
||||||
|
DPRINTF_S(keyname(*ch));
|
||||||
|
|
||||||
|
/* If there's a filter, try a command on ^P */
|
||||||
|
if (cfg.filtercmd && *ch == CONTROL('P') && len > 1) {
|
||||||
|
spawn(shell, "-c", pln, path, F_CLI | F_CMD);
|
||||||
|
*ch = CONTROL('L');
|
||||||
|
}
|
||||||
|
|
||||||
if (len == 1)
|
if (len == 1)
|
||||||
cur = oldcur;
|
cur = oldcur;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (*ch) {
|
switch (*ch) {
|
||||||
case '\r': /* with nonl(), this is ENTER key value */
|
|
||||||
if (len == 1) {
|
|
||||||
cur = oldcur;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matches(pln) == -1)
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
redraw(path);
|
|
||||||
goto end;
|
|
||||||
case '/': /* works as Leader key in filter mode */
|
case '/': /* works as Leader key in filter mode */
|
||||||
*ch = CONTROL('_'); // fallthrough
|
*ch = CONTROL('_'); // fallthrough
|
||||||
if (len == 1)
|
if (len == 1)
|
||||||
|
@ -4528,7 +4526,7 @@ nochange:
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stdout,
|
fprintf(stdout,
|
||||||
"%s: nnn [-a] [-b key] [-d] [-H] [-i] [-n] [-o]\n"
|
"%s: nnn [-a] [-b key] [-d] [-f] [-H] [-i] [-n] [-o]\n"
|
||||||
" [-p file] [-r] [-s] [-S] [-t] [-v] [-h] [PATH]\n\n"
|
" [-p file] [-r] [-s] [-S] [-t] [-v] [-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"
|
||||||
|
@ -4537,6 +4535,7 @@ static void usage(void)
|
||||||
" -a use access time\n"
|
" -a use access time\n"
|
||||||
" -b key open bookmark key\n"
|
" -b key open bookmark key\n"
|
||||||
" -d detail mode\n"
|
" -d detail mode\n"
|
||||||
|
" -f run filter as cmd on ^P\n"
|
||||||
" -H show hidden files\n"
|
" -H show hidden files\n"
|
||||||
" -i nav-as-you-type mode\n"
|
" -i nav-as-you-type mode\n"
|
||||||
" -n version sort\n"
|
" -n version sort\n"
|
||||||
|
@ -4681,7 +4680,7 @@ int main(int argc, char *argv[])
|
||||||
bool progress = FALSE;
|
bool progress = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "HSiab:dnop:rstvh")) != -1) {
|
while ((opt = getopt(argc, argv, "HSiab:dfnop:rstvh")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'S':
|
case 'S':
|
||||||
cfg.blkorder = 1;
|
cfg.blkorder = 1;
|
||||||
|
@ -4700,6 +4699,9 @@ int main(int argc, char *argv[])
|
||||||
case 'b':
|
case 'b':
|
||||||
arg = optarg;
|
arg = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
cfg.filtercmd = 1;
|
||||||
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
cfg.showhidden = 1;
|
cfg.showhidden = 1;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue