Add option -s to use string filters

This commit is contained in:
Arun Prakash Jana 2019-02-06 00:38:55 +05:30
parent 512d217392
commit cebb2469d3
No known key found for this signature in database
GPG Key ID: A75979F35C080412
6 changed files with 19 additions and 19 deletions

View File

@ -189,7 +189,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] [-v] [-h] [PATH] [-p file] [-s] [-S] [-v] [-h] [PATH]
The missing terminal file manager for X. The missing terminal file manager for X.
@ -204,6 +204,7 @@ optional args:
-l light mode -l light mode
-n use version compare to sort -n use version compare to sort
-p file selection file (stdout if '-') -p file selection file (stdout if '-')
-s string filters [default: regex]
-S disk usage mode -S disk usage mode
-v show version -v show version
-h show help -h show help
@ -320,9 +321,7 @@ Common use cases:
- type `\.mkv` to list all MKV files - type `\.mkv` to list all MKV files
- use `.*` to match any character (_sort of_ fuzzy search) - use `.*` to match any character (_sort of_ fuzzy search)
To filter entries by substring match: There is a program opton to filter entries by substring match.
export NNN_PLAIN_FILTER=1
If `nnn` is invoked as root or the environment variable `NNN_SHOW_HIDDEN` is set the default filter will also match hidden files. If `nnn` is invoked as root or the environment variable `NNN_SHOW_HIDDEN` is set the default filter will also match hidden files.
@ -396,7 +395,6 @@ The option `open with` takes 1 combined argument.
| `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type` mode | | `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type` mode |
| `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd></kbd>, not <kbd></kbd> or <kbd>l</kbd> | | `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd></kbd>, not <kbd></kbd> or <kbd>l</kbd> |
| `NNN_RESTRICT_0B=1` | do not open 0-byte files | | `NNN_RESTRICT_0B=1` | do not open 0-byte files |
| `NNN_PLAIN_FILTER=1` | use substring match in filer mode [default: regex] |
#### Help #### Help

12
nnn.1
View File

@ -11,7 +11,9 @@
.Op Ar -e .Op Ar -e
.Op Ar -i .Op Ar -i
.Op Ar -l .Op Ar -l
.Op Ar -n
.Op Ar -p file .Op Ar -p file
.Op Ar -s
.Op Ar -S .Op Ar -S
.Op Ar -v .Op Ar -v
.Op Ar -h .Op Ar -h
@ -187,6 +189,9 @@ supports the following options:
.Fl "p file" .Fl "p file"
copy (or \fIpick\fR) selection to file, or stdout if file='-' copy (or \fIpick\fR) selection to file, or stdout if file='-'
.Pp .Pp
.Fl s
use substring match for filters instead of regex
.Pp
.Fl S .Fl S
start in disk usage analyzer mode start in disk usage analyzer mode
.Pp .Pp
@ -235,7 +240,7 @@ with a '^' (caret) symbol.
.br .br
(3) Use '.*' to match any character (\fIsort of\fR fuzzy search). (3) Use '.*' to match any character (\fIsort of\fR fuzzy search).
.Pp .Pp
To filter entries by substring match export the environment variable \fBNNN_PLAIN_FILTER\fR. There is a program option to filter entries by substring match.
.Pp .Pp
If If
.Nm .Nm
@ -335,11 +340,6 @@ files.
.Bd -literal .Bd -literal
export NNN_RESTRICT_0B=1 export NNN_RESTRICT_0B=1
.Ed .Ed
.Pp
\fBNNN_PLAIN_FILTER:\fR use substring match in filter mode.
.Bd -literal
export NNN_PLAIN_FILTER=1
.Ed
.Sh KNOWN ISSUES .Sh KNOWN ISSUES
If you are using urxvt you might have to set backspace key to DEC. If you are using urxvt you might have to set backspace key to DEC.
.Sh AUTHORS .Sh AUTHORS

View File

@ -19,6 +19,7 @@ _nnn () {
-l -l
-n -n
-p -p
-s
-S -S
-v -v
) )

View File

@ -13,5 +13,6 @@ complete -c nnn -s i -d 'start in navigate-as-you-type mode'
complete -c nnn -s l -d 'start in light mode (fewer details)' complete -c nnn -s l -d 'start in light mode (fewer details)'
complete -c nnn -s n -d 'use version compare to sort files' complete -c nnn -s n -d 'use version compare to sort files'
complete -c nnn -s p -r -d 'copy selection to file' 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 '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'

View File

@ -17,6 +17,7 @@ args=(
'(-l)-l[start in light mode (fewer details)]' '(-l)-l[start in light mode (fewer details)]'
'(-n)-n[use version compare to sort files]' '(-n)-n[use version compare to sort files]'
'(-p)-p[copy selection to file]:file name' '(-p)-p[copy selection to file]:file name'
'(-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]'
'*:filename:_files' '*:filename:_files'

View File

@ -3956,7 +3956,7 @@ static void usage(void)
{ {
fprintf(stdout, fprintf(stdout,
"usage: nnn [-b key] [-C] [-e] [-i] [-l] [-n]\n" "usage: nnn [-b key] [-C] [-e] [-i] [-l] [-n]\n"
" [-p file] [-S] [-v] [-h] [PATH]\n\n" " [-p file] [-s] [-S] [-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"
" PATH start dir [default: current dir]\n\n" " PATH start dir [default: current dir]\n\n"
@ -3968,6 +3968,7 @@ static void usage(void)
" -l light mode\n" " -l light mode\n"
" -n use version compare to sort\n" " -n use version compare to sort\n"
" -p file selection file (stdout if '-')\n" " -p file selection file (stdout if '-')\n"
" -s string filters [default: regex]\n"
" -S disk usage mode\n" " -S disk usage mode\n"
" -v show version\n" " -v show version\n"
" -h show help\n\n" " -h show help\n\n"
@ -3980,7 +3981,7 @@ int main(int argc, char *argv[])
char *ipath = NULL; char *ipath = NULL;
int opt; int opt;
while ((opt = getopt(argc, argv, "Slib:Cenp:vh")) != -1) { while ((opt = getopt(argc, argv, "Slib:Cenp:svh")) != -1) {
switch (opt) { switch (opt) {
case 'S': case 'S':
cfg.blkorder = 1; cfg.blkorder = 1;
@ -4019,6 +4020,10 @@ int main(int argc, char *argv[])
} }
} }
break; break;
case 's':
cfg.filter_re = 0;
filterfn = &visible_str;
break;
case 'v': case 'v':
fprintf(stdout, "%s\n", VERSION); fprintf(stdout, "%s\n", VERSION);
return 0; return 0;
@ -4168,12 +4173,6 @@ int main(int argc, char *argv[])
if (getenv(env_cfg[NNN_RESTRICT_0B])) if (getenv(env_cfg[NNN_RESTRICT_0B]))
cfg.restrict0b = 1; cfg.restrict0b = 1;
/* Use string-comparison in filter mode */
if (getenv(env_cfg[NNN_PLAIN_FILTER])) {
cfg.filter_re = 0;
filterfn = &visible_str;
}
/* Ignore certain signals */ /* Ignore certain signals */
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN); signal(SIGQUIT, SIG_IGN);