From 3e053e9412bedb10f2a171ddfbbd72e7432a9bda Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Wed, 27 Feb 2019 21:03:14 +0530 Subject: [PATCH] Wild mode for nav-as-you-type --- README.md | 9 ++-- nnn.1 | 8 ++++ .../auto-completion/bash/nnn-completion.bash | 1 + scripts/auto-completion/fish/nnn.fish | 1 + scripts/auto-completion/zsh/_nnn | 1 + src/nnn.c | 41 ++++++++++++++----- src/nnn.h | 3 ++ 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 215058e4..1623e6fc 100644 --- a/README.md +++ b/README.md @@ -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] - [-p file] [-s] [-S] [-v] [-h] [PATH] + [-p file] [-s] [-S] [-v] [-w] [-h] [PATH] The missing terminal file manager for X. @@ -228,11 +228,10 @@ optional args: -s string filters [default: regex] -S du mode -v show version + -w wild mode -h show help ``` -`>` indicates the currently selected entry in `nnn`. - #### Keyboard shortcuts Press ? in `nnn` to see the list anytime. @@ -264,7 +263,7 @@ Press ? in `nnn` to see the list anytime. e Edit in EDITOR p Open in PAGER ORDER TOGGLES ^J Disk usage S Apparent du - t Time modified s Size + ^W Random s Size t Time modified MISC ! ^] Spawn SHELL C Execute entry 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 +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 The following indicators are used in the detail view: diff --git a/nnn.1 b/nnn.1 index 1a42db47..73ec86ea 100644 --- a/nnn.1 +++ b/nnn.1 @@ -16,6 +16,7 @@ .Op Ar -s .Op Ar -S .Op Ar -v +.Op Ar -w .Op Ar -h .Op Ar PATH .Sh DESCRIPTION @@ -135,6 +136,8 @@ ORDER TOGGLES Toggle disk usage analyzer mode .It Ic S Toggle sort by apparent size +.It Ic ^W +Wild mode .It Ic t Toggle sort by time modified .It Ic s @@ -198,6 +201,9 @@ supports the following options: .Fl v show version and exit .Pp +.Fl w + wild mode - entries unsorted on directory load +.Pp .Fl h show program help and exit .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. .br 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 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). diff --git a/scripts/auto-completion/bash/nnn-completion.bash b/scripts/auto-completion/bash/nnn-completion.bash index 095adb99..7a265bc3 100644 --- a/scripts/auto-completion/bash/nnn-completion.bash +++ b/scripts/auto-completion/bash/nnn-completion.bash @@ -22,6 +22,7 @@ _nnn () { -s -S -v + -w ) opts_with_arg=( -b diff --git a/scripts/auto-completion/fish/nnn.fish b/scripts/auto-completion/fish/nnn.fish index 3ec36eb5..f6e86a43 100644 --- a/scripts/auto-completion/fish/nnn.fish +++ b/scripts/auto-completion/fish/nnn.fish @@ -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 'start in disk usage analyzer mode' complete -c nnn -s v -d 'show program version and exit' +complete -c nnn -s w -d 'wild mode' diff --git a/scripts/auto-completion/zsh/_nnn b/scripts/auto-completion/zsh/_nnn index 9171a913..0ec80334 100644 --- a/scripts/auto-completion/zsh/_nnn +++ b/scripts/auto-completion/zsh/_nnn @@ -20,6 +20,7 @@ args=( '(-s)-s[use substring match for filters]' '(-S)-S[start in disk usage analyzer mode]' '(-v)-v[show program version and exit]' + '(-w)-w[wild mode]' '*:filename:_files' ) _arguments -S -s $args diff --git a/src/nnn.c b/src/nnn.c index cbad15e3..14f72e10 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -285,7 +285,7 @@ typedef struct { uint dircolor : 1; /* Current status of dir color */ uint metaviewer : 1; /* Index of metadata viewer in utils[] */ uint ctxactive : 1; /* Context active or not */ - uint reserved : 8; + uint reserved : 7; /* The following settings are global */ uint curctx : 2; /* Current context number */ 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 restrict0b : 1; /* Restrict 0-byte file opening */ uint filter_re : 1; /* Use regex filters */ + uint wild : 1; /* Do not sort entries on dir load */ } settings; /* Contexts or workspaces */ @@ -311,7 +312,7 @@ typedef struct { /* GLOBALS */ /* 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 struct entry *dents; @@ -2443,7 +2444,7 @@ static bool show_help(char *path) "ce Edit in EDITOR p Open in PAGER\n" "1ORDER TOGGLES\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" "9! ^] Spawn SHELL C Execute entry\n" "9R ^V Run/pick script L Lock terminal\n" @@ -2727,7 +2728,8 @@ static void populate(char *path, char *lastname) if (!ndents) return; - qsort(dents, ndents, sizeof(*dents), entrycmp); + if (!cfg.wild) + qsort(dents, ndents, sizeof(*dents), entrycmp); #ifdef DBGMODE clock_gettime(CLOCK_REALTIME, &ts2); @@ -2834,7 +2836,7 @@ static void redraw(char *path) else ncols -= 5; - if (cfg.showcolor) { + if (!cfg.wild && cfg.showcolor) { attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); cfg.dircolor = 1; } @@ -3301,6 +3303,7 @@ nochange: } #endif presel = filterentries(path); + /* Save current */ if (ndents) copycurname(); @@ -3311,7 +3314,8 @@ nochange: case SEL_FSIZE: // fallthrough case SEL_ASIZE: // fallthrough case SEL_BSIZE: // fallthrough - case SEL_MTIME: + case SEL_MTIME: // fallthrough + case SEL_WILD: switch (sel) { case SEL_MFLTR: cfg.filtermode ^= 1; @@ -3336,6 +3340,7 @@ nochange: cfg.apparentsz = 0; cfg.blkorder = 0; cfg.copymode = 0; + cfg.wild = 0; break; case SEL_ASIZE: cfg.apparentsz ^= 1; @@ -3344,8 +3349,7 @@ nochange: cfg.blkorder = 1; BLK_SHIFT = 0; } else - cfg.blkorder = 0; - break; + cfg.blkorder = 0; // fallthrough case SEL_BSIZE: if (sel == SEL_BSIZE) { if (!cfg.apparentsz) @@ -3362,14 +3366,25 @@ nochange: cfg.mtimeorder = 0; cfg.sizeorder = 0; cfg.copymode = 0; + cfg.wild = 0; break; - default: /* SEL_MTIME */ + case SEL_MTIME: cfg.mtimeorder ^= 1; cfg.sizeorder = 0; cfg.apparentsz = 0; cfg.blkorder = 0; cfg.copymode = 0; + cfg.wild = 0; 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 */ @@ -4013,7 +4028,7 @@ static void usage(void) { fprintf(stdout, "%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" "positional args:\n" " PATH start dir [default: current dir]\n\n" @@ -4028,6 +4043,7 @@ static void usage(void) " -s string filters [default: regex]\n" " -S du mode\n" " -v show version\n" + " -w wild mode\n" " -h show help\n\n" "v%s\n%s\n", __func__, VERSION, GENERAL_INFO); } @@ -4038,7 +4054,7 @@ int main(int argc, char *argv[]) char *ipath = NULL; int opt; - while ((opt = getopt(argc, argv, "Slib:Cenp:svh")) != -1) { + while ((opt = getopt(argc, argv, "Slib:Cenp:svwh")) != -1) { switch (opt) { case 'S': cfg.blkorder = 1; @@ -4084,6 +4100,9 @@ int main(int argc, char *argv[]) case 'v': fprintf(stdout, "%s\n", VERSION); return 0; + case 'w': + cfg.wild = 1; + break; case 'h': usage(); return 0; diff --git a/src/nnn.h b/src/nnn.h index a588a33f..a2a858bf 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -70,6 +70,7 @@ enum action { SEL_ASIZE, /* apparent size */ SEL_BSIZE, /* block size */ SEL_MTIME, + SEL_WILD, SEL_REDRAW, SEL_COPY, SEL_COPYMUL, @@ -183,6 +184,8 @@ static struct key bindings[] = { { CONTROL('J'), SEL_BSIZE }, /* Toggle sort by time */ { 't', SEL_MTIME }, + /* Wild mode */ + { CONTROL('W'), SEL_WILD }, /* Redraw window */ { CONTROL('L'), SEL_REDRAW }, /* Copy currently selected file path */