]> Sergey Matveev's repositories - nnn.git/commitdiff
Q - error & quit if no selection, else pick & quit
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 13 Nov 2020 07:10:57 +0000 (12:40 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 13 Nov 2020 07:10:57 +0000 (12:40 +0530)
README.md
src/nnn.c
src/nnn.h

index a2cc92355c8b19129d2f717efa4e1a47216503d5..a7072ce08597c9109ee9b3b3b100495562923963 100644 (file)
--- a/README.md
+++ b/README.md
@@ -37,6 +37,7 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/embed/AbaauM7gUJw)
 <details><summary><i><b>Expand</b></i> for some nnn magic! :dark_sunglasses:</summary><br><ul>
   <li>Instantly load, sort, filter thousands of files</li>
   <li>Type to navigate with automatic dir selection</li>
+  <li>List input stream and pick entries to stdout or file</li>
   <li>find/fd/grep/ripgrep/fzf from nnn and list in nnn</li>
   <li> Never lose context - start where you quit</li>
   <li>Mount any cloud storage service in a few keypresses</li>
index 78c95468b0bafd581f92f9ca6f29de89b3b88278..466acaf1bd25d0c47ca0c7b04676150cc352276f 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4602,6 +4602,7 @@ static void show_help(const char *path)
                "aEsc  Send to FIFO%-11c^L  Redraw\n"
                  "c?  Help, conf%-13c^G  QuitCD\n"
                  "cq  Quit context%-6c^Q 2Esc  Quit\n"
+                 "cQ  Pick sel/err & quit\n"
                "1FILTER & PROMPT\n"
                  "c/  Filter%-12cAlt+Esc  Clear filter & redraw\n"
                "aEsc  Exit prompt%-12c^L  Clear prompt/last filter\n"
@@ -7036,7 +7037,7 @@ nochange:
                case SEL_QUITCTX: // fallthrough
                case SEL_QUITCD: // fallthrough
                case SEL_QUIT:
-               case SEL_QUITFAIL:
+               case SEL_QUITERR:
                        if (sel == SEL_QUITCTX) {
                                int ctx = cfg.curctx;
                                for (r = (ctx + 1) & ~CTX_MAX;
@@ -7086,7 +7087,16 @@ nochange:
                                if (g_state.picker)
                                        selbufpos = 0;
                        }
-                       return sel == SEL_QUITFAIL ? EXIT_FAILURE : EXIT_SUCCESS;
+
+                       if (sel != SEL_QUITERR)
+                               return EXIT_SUCCESS;
+
+                       if (selbufpos && !g_state.picker) {
+                               g_state.pickraw = 1;
+                               return EXIT_SUCCESS;
+                       }
+
+                       return EXIT_FAILURE;
                default:
                        if (xlines != LINES || xcols != COLS)
                                continue;
@@ -7926,7 +7936,7 @@ int main(int argc, char *argv[])
 
        if (g_state.pickraw || g_state.picker) {
                if (selbufpos) {
-                       fd = g_state.pickraw ? 1 : open(selpath, O_WRONLY | O_CREAT, 0600);
+                       fd = g_state.pickraw ? STDOUT_FILENO : open(selpath, O_WRONLY | O_CREAT, 0600);
                        if ((fd == -1) || (seltofile(fd, NULL) != (size_t)(selbufpos)))
                                xerror();
 
index 55ceacfb5177c0ca5e07e2aa6c33f17239d5d774..222d1a955b34587534e6e0cd505799973d49a606 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -111,7 +111,7 @@ enum action {
        SEL_QUITCTX,
        SEL_QUITCD,
        SEL_QUIT,
-       SEL_QUITFAIL,
+       SEL_QUITERR,
 #ifndef NOMOUSE
        SEL_CLICK,
 #endif
@@ -270,7 +270,7 @@ static struct key bindings[] = {
        /* Quit */
        { CONTROL('Q'),   SEL_QUIT },
        /* Quit with an error code */
-       { 'Q',            SEL_QUITFAIL },
+       { 'Q',            SEL_QUITERR },
 #ifndef NOMOUSE
        { KEY_MOUSE,      SEL_CLICK },
 #endif