]> Sergey Matveev's repositories - nnn.git/commitdiff
Support multiple scripts
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 17 Jun 2018 16:17:19 +0000 (21:47 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 17 Jun 2018 16:17:19 +0000 (21:47 +0530)
README.md
nnn.1
nnn.c

index d8cd0fc51a0be34e1815e61923e9820050362677..d353c25188a953572f49193d8f7bff5647ace03f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To
   - [cd on quit](#cd-on-quit)
   - [copy file paths to clipboard](#copy-file-paths-to-clipboard)
   - [copy file paths when X is missing](#copy-file-paths-when-x-is-missing)
-  - [run a custom script](#run-a-custom-script)
+  - [run custom scripts](#run-custom-scripts)
   - [change dir color](#change-dir-color)
   - [file copy, move, delete](#file-copy-move-delete)
   - [boost chdir prompt](#boost-chdir-prompt)
@@ -100,7 +100,7 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To
   - Create, rename files and directories
   - Batch rename/move/delete current directory entries in vidir (from moreutils)
   - Spawn SHELL (fallback sh) in the current directory
-  - Run a custom script in the current directory
+  - Run custom scripts in the current directory
   - Copy absolute file paths with/without X (*easy* shell integration)
   - Change directory at exit (*easy* shell integration)
   - Open any file in EDITOR (fallback vi) or PAGER (fallback less)
@@ -416,7 +416,7 @@ so you can -
 
 Note that you may want to keep quotes disabled in this case.
 
-#### run a custom script
+#### run custom scripts
 
 Export the path to the custom executable script:
 
@@ -436,6 +436,20 @@ Sample (fish shell) script to fuzzy find files in fzy and open with xdg-open:
 
 Press <kbd>R</kbd> to run the script in the current directory.
 
+It's possible to run multiple scripts with `nnn` as long as the scripts are in the same location and share the same prefix. To enable multiple scripts,
+
+    export NNN_MULTISCRIPT=1
+
+With the example of `NNN_SCRIPT` above, some more scripts could be:
+
+    /usr/local/bin/nscript1
+    /usr/local/bin/nscript2
+    /usr/local/bin/nscriptcustom1
+    /usr/local/bin/nscriptcustom2
+    and so on...
+
+Type the correct suffix  when prompted on pressing the keybind <kbd>R</kbd>. To use the base script (`NNN_SCRIPT`), just press <kbd>Enter</kbd>.
+
 #### change dir color
 
 The default color for directories is blue. Option `-c` accepts color codes from 0 to 7 to use a different color:
diff --git a/nnn.1 b/nnn.1
index 368980d6c115744422fb0d6951b753d44745c78c..6735684d285a95f69a9fec7bac188266331b1238 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -265,8 +265,14 @@ names in the shell.
 .Pp
 \fBNNN_SCRIPT:\fR path to a custom script to run.
 .Bd -literal
-    export NNN_SCRIPT=/usr/local/bin/script.sh
+    export NNN_SCRIPT=/usr/local/bin/nscript
 .Ed
+.Pp
+\fBNNN_MULTISCRIPT:\fR run multiple custom scripts.
+.Bd -literal
+    export NNN_MULTISCRIPT=1
+.Ed
+.Pp
 \fBNNN_SHOW_HIDDEN:\fR show hidden files.
 .Bd -literal
     export NNN_SHOW_HIDDEN=1
diff --git a/nnn.c b/nnn.c
index 22aafc7e732d924484ca909f8501eebd4776c6b8..f213b4e0887fdecd0f9f2afe07df3c3c449bdb9b 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -2005,6 +2005,8 @@ show_help(char *path)
                dprintf(fd, "NNN_NO_X: %s (%s)\n", getenv("NNN_NO_X"), g_cppath);
        if (getenv("NNN_SCRIPT"))
                dprintf(fd, "NNN_SCRIPT: %s\n", getenv("NNN_SCRIPT"));
+       if (getenv("NNN_MULTISCRIPT"))
+               dprintf(fd, "NNN_MULTISCRIPT: %s\n", getenv("NNN_MULTISCRIPT"));
        if (getenv("NNN_SHOW_HIDDEN"))
                dprintf(fd, "NNN_SHOW_HIDDEN: %s\n", getenv("NNN_SHOW_HIDDEN"));
 
@@ -3228,8 +3230,17 @@ nochange:
 
                        if (sel == SEL_RUNSCRIPT) {
                                tmp = getenv("NNN_SCRIPT");
-                               if (tmp)
+                               if (tmp) {
+                                       if (getenv("NNN_MULTISCRIPT")) {
+                                               size_t _len = xstrlcpy(newpath, tmp, PATH_MAX);
+                                               tmp = xreadline(NULL, "script suffix: ");
+                                               if (tmp && tmp[0])
+                                                       xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len);
+
+                                               tmp = newpath;
+                                       }
                                        spawn(run, tmp, NULL, path, F_NORMAL | F_SIGINT);
+                               }
                        } else {
                                spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER);