]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix broken GUI cmd run as plugin case
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 25 Sep 2021 18:24:12 +0000 (23:54 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 25 Sep 2021 18:25:25 +0000 (23:55 +0530)
nnn.1
plugins/README.md
src/nnn.c

diff --git a/nnn.1 b/nnn.1
index d25452bca3f7a647de648a05d1bb4ffbdd7fd8b6..a2989027138b5509e682d2075a0cc76db7f72fcd 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -401,6 +401,7 @@ separated by \fI;\fR:
         export NNN_PLUG='y:-!sync*'
 
     5. To run a \fIGUI app as plugin\fR, add a \fB&\fR after \fB!\fR
+       Note: $nnn must be the last argument in this case.
 
         export NNN_PLUG='m:-!&mousepad $nnn'
 
index 68eb9018c82b1d39fa787d578cac84b23a2a0d60..55826d8943f24837dc6b7fd161f3a238e35354de 100644 (file)
@@ -165,6 +165,8 @@ To run a GUI app as plugin, add a `&` after `!`.
 export NNN_PLUG='m:-!&mousepad $nnn'
 ```
 
+Note: $nnn must be the last argument in this case.
+
 #### Page non-interactive command output
 
 To show the output of run-and-exit commands which do not need user input, add `|` (pipe) after `!`.
index 44f297f475b0fa9fa69351453ae465e3410ffdbe..9ad79e3439099c43e96d63378d9247f7fd85cb1e 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -5108,7 +5108,7 @@ static void setexports(void)
        }
 }
 
-static bool run_cmd_as_plugin(const char *file, uchar_t flags)
+static bool run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
 {
        size_t len;
 
@@ -5122,8 +5122,14 @@ static bool run_cmd_as_plugin(const char *file, uchar_t flags)
        }
 
        if (flags & F_PAGE)
-               get_output(utils[UTIL_SH_EXEC], g_buf, NULL, -1, TRUE, TRUE);
-       else
+               get_output(g_buf, NULL, NULL, -1, TRUE, TRUE);
+       else if (flags & F_NOTRACE) {
+               if (is_suffix(g_buf, " $nnn"))
+                       g_buf[len - 5] = '\0';
+               else
+                       runfile = NULL;
+               spawn(g_buf, runfile, NULL, NULL, flags);
+       } else
                spawn(utils[UTIL_SH_EXEC], g_buf, NULL, NULL, flags);
 
        return TRUE;
@@ -5257,7 +5263,7 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last
                        return FALSE;
 
                if ((flags & F_NOTRACE) || (flags & F_PAGE))
-                       return run_cmd_as_plugin(file, flags);
+                       return run_cmd_as_plugin(file, runfile, flags);
 
                cmd_as_plugin = TRUE;
        }
@@ -5291,7 +5297,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, flags);
+                       run_cmd_as_plugin(file, NULL, flags);
 
                close(wfd);
                _exit(EXIT_SUCCESS);