]> Sergey Matveev's repositories - nnn.git/commitdiff
Simplify paged and GUI commands run as plugin
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 28 Jan 2023 03:41:15 +0000 (09:11 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 28 Jan 2023 03:46:06 +0000 (09:16 +0530)
nnn.1
plugins/README.md
src/nnn.c

diff --git a/nnn.1 b/nnn.1
index 61532ab573e22c6fbd050f404b3e692d815f51e3..7025d6a4660da41fe916626e7c303aeaaf0d29f2 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -423,14 +423,14 @@ separated by \fI;\fR:
     To assign keys to arbitrary non-background cli commands and invoke like
     plugins, add \fB!\fR before the command.
 .Bd -literal
-    export NNN_PLUG='x:!chmod +x $nnn;g:!git log;s:!smplayer $nnn'
+    export NNN_PLUG='x:!chmod +x "$nnn";g:!git log;s:!smplayer "$nnn"'
 
     To pick and run an unassigned plugin, press \fBEnter\fR at the plugin prompt.
     To run a plugin at startup, use the option `-P` followed by the plugin key.
 
     NOTES:
-    1. Use single quotes for $NNN_PLUG so $nnn is not interpreted
-    2. $nnn must be the last argument (if used) to run a \fIcommand as plugin\fR
+    1. Place $nnn in double quotes (\fB"$nnn"\fR)
+    2. Use single quotes for $NNN_PLUG so "$nnn" is not interpreted
     3. (Again) add \fB!\fR before the command
     4. To disable directory refresh after running a \fIcommand as plugin\fR,
        prefix with \fB-!\fR
@@ -439,18 +439,16 @@ separated by \fI;\fR:
 
         export NNN_PLUG='y:-!sync*'
 
-    6. To run a \fIGUI app as plugin\fR, add a \fB&\fR after \fB!\fR
-       \fI$nnn\fR must be the last argument in this case.
+    6. To run a \fIGUI app as plugin\fR, add a \fB&\fR after \fB!\fR.
 
-        export NNN_PLUG='m:-!&mousepad $nnn'
+        export NNN_PLUG='m:-!&mousepad "$nnn"'
 
     7. To show the output of run-and-exit commands which do not need user input,
        add \fB|\fR (pipe) after \fB!\fR
        Note: This option is incompatible with \fB&\fR (terminal output is masked
        for GUI programs) and ignores \fB*\fR (output is already paged for user).
-       \fI$nnn\fR must be the last argument in this case as well.
 
-        export NNN_PLUG='m:-!|mediainfo $nnn;t:-!|tree -ps;l:-!|ls -lah --group-directories-first'
+        export NNN_PLUG='m:-!|mediainfo "$nnn";t:-!|tree -ps;l:-!|ls -lah --group-directories-first'
 
     EXAMPLES:
     ------------------------------------ + -------------------------------------------------
index 2a7aeef908e33c352136c51c7475228b186a2328..5d749c1733e7d6b73223fa29ef060e47fb16adfc 100644 (file)
@@ -180,10 +180,10 @@ export NNN_PLUG='m:-!|mediainfo "$nnn";t:-!|tree -ps;l:-!|ls -lah --group-direct
 This option is incompatible with `&` (terminal output is masked for GUI programs) and ignores `*` (output is already paged for user).
 
 Notes:
-
-1. Use single quotes for `$NNN_PLUG` so `"$nnn"` is not interpreted
-2. (_Again_) add `!` before the command
-3. To disable directory refresh after running a _command as plugin_, prefix with `-!`
+1. Place `$nnn` in double quotes (**`"$nnn"`**)
+2. Use single quotes for `$NNN_PLUG` so `"$nnn"` is not interpreted
+3. (_Again_) add `!` before the command
+4. To disable directory refresh after running a _command as plugin_, prefix with `-!`
 
 #### Some useful key-command examples
 
index 6be52e3fe78c8bc10601bb4a2248be8b713c73cc..17e97da90daf1b0322656a925da334a79d2c239e 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -5175,7 +5175,7 @@ static void setexports(void)
        setenv("NNN_INCLUDE_HIDDEN", xitoa(cfg.showhidden), 1);
 }
 
-static void run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
+static void run_cmd_as_plugin(const char *file, uchar_t flags)
 {
        size_t len;
 
@@ -5188,16 +5188,6 @@ static void run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
                --len;
        }
 
-       /* This is to catch the old way of doing things so we don't break users' configs */
-       if ((flags & (F_PAGE | F_NOTRACE)) && is_suffix(g_buf, " $nnn")) {
-               g_buf[len - 5] = '\0';
-
-               if (flags & F_PAGE)
-                       get_output(g_buf, runfile, NULL, -1, TRUE);
-               else // F_NOTRACE
-                       spawn(g_buf, runfile, NULL, NULL, flags);
-       }
-
        if (flags & F_PAGE)
                get_output(utils[UTIL_SH_EXEC], g_buf, NULL, -1, TRUE);
        else
@@ -5324,7 +5314,7 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last
                        flags |= F_PAGE;
                        ++file;
                } else if (*file == '&') { /* Check if GUI flags are to be used */
-                       flags = F_NOTRACE | F_NOWAIT;
+                       flags = F_MULTI | F_NOTRACE | F_NOWAIT;
                        ++file;
                }
 
@@ -5332,7 +5322,7 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last
                        return FALSE;
 
                if ((flags & F_NOTRACE) || (flags & F_PAGE)) {
-                       run_cmd_as_plugin(file, runfile, flags);
+                       run_cmd_as_plugin(file, flags);
                        return TRUE;
                }
 
@@ -5368,7 +5358,7 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last
                        } else
                                spawn(g_buf, NULL, *path, sel, 0);
                } else
-                       run_cmd_as_plugin(file, runfile, flags);
+                       run_cmd_as_plugin(file, flags);
 
                close(wfd);
                _exit(EXIT_SUCCESS);