nnn.1 | 1 + plugins/README.md | 2 ++ src/nnn.c | 16 +++++++++++----- diff --git a/nnn.1 b/nnn.1 index d25452bca3f7a647de648a05d1bb4ffbdd7fd8b6..a2989027138b5509e682d2075a0cc76db7f72fcd 100644 --- a/nnn.1 +++ b/nnn.1 @@ -401,6 +401,7 @@ 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' diff --git a/plugins/README.md b/plugins/README.md index 68eb9018c82b1d39fa787d578cac84b23a2a0d60..55826d8943f24837dc6b7fd161f3a238e35354de 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -165,6 +165,8 @@ ```sh 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 `!`. diff --git a/src/nnn.c b/src/nnn.c index 44f297f475b0fa9fa69351453ae465e3410ffdbe..9ad79e3439099c43e96d63378d9247f7fd85cb1e 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -5108,7 +5108,7 @@ } } } -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 @@ --len; } 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 @@ if (!*file) 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 @@ spawn(g_buf, *lastname, *path, sel, 0); } 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);