]> Sergey Matveev's repositories - nnn.git/commitdiff
Simplify running commands
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 16 Nov 2019 01:50:18 +0000 (07:20 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 16 Nov 2019 01:50:18 +0000 (07:20 +0530)
plugins/README.md
src/nnn.c

index e02448886b7a09af8f902f4c02b96b836bec9689..fcf514023bf0321ac811fcf922c2b880e5515590 100644 (file)
@@ -68,7 +68,11 @@ With this, plugin `fzy-open` can be run with the keybind <kbd>:o</kbd>, `mocplay
 
 To assign keys to arbitrary non-background cli commands (non-shell-interpreted) and invoke like plugins, add `_` (underscore) before the command. For example:
 
-    export NNN_PLUG='x:_chmod +x;o:fzy-open'
+    export NNN_PLUG='x:_chmod +x $NNN;g:_git log;s:_smplayer $NNN;o:fzy-open'
+    Notes:
+      1. use single quotes for $NNN_PLUG so $NNN is not interpreted
+      2. $NNN should be the last argument (IF you want to pass the hovered file name)
+      3. (_again_) add `_` before the command
 
 **Method 2:** Use the _pick plugin_ shortcut to visit the plugin directory and execute a plugin. Repeating the same shortcut cancels the operation and puts you back in the original directory.
 
index 42107d996793ea40d0381b76b9e9e76c9cbf4b3d..5d5fff45aa4c697753f902156d5b5b6f56eb3aa7 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4970,8 +4970,14 @@ nochange:
 
                                        if (tmp[0] == '_' && tmp[1]) {
                                                xstrlcpy(newpath, ++tmp, PATH_MAX);
-                                               spawn(newpath, (ndents ? dents[cur].name : NULL),
-                                                     NULL, path, F_CLI | F_CONFIRM);
+                                               if (is_suffix(newpath, " $NNN")) {
+                                                       tmp = (ndents ? dents[cur].name : NULL);
+                                                       /* Set `\0` to clear ' $NNN' suffix */
+                                                       newpath[strlen(newpath) - 5] = '\0';
+                                               } else
+                                                       tmp = NULL;
+
+                                               spawn(newpath, tmp, NULL, path, F_CLI | F_CONFIRM);
                                        } else {
                                                if (!run_selected_plugin(&path, tmp, newpath, NULL,
                                                                (ndents ? dents[cur].name : NULL),
@@ -4981,6 +4987,9 @@ nochange:
                                                        goto nochange;
                                                }
                                        }
+
+                                       if (ndents)
+                                               copycurname();
                                } else {
                                        cfg.runplugin ^= 1;
                                        if (!cfg.runplugin && rundir[0]) {