nnn.1 | 11 ++++++----- plugins/README.md | 5 +++-- src/nnn.c | 22 ++++++++++++---------- diff --git a/nnn.1 b/nnn.1 index ebd1dd9e5a8b50b402ffbb4e803a9a50a749120c..35df524d524c03addf615d5a9fec00dee557f2f6 100644 --- a/nnn.1 +++ b/nnn.1 @@ -410,20 +410,21 @@ 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. (Again) add \fB!\fR before the command - 3. To disable directory refresh after running a \fIcommand as plugin\fR, + 2. $nnn must be the last argument (if used) to run a \fIcommand as plugin\fR + 3. (Again) add \fB!\fR before the command + 4. To disable directory refresh after running a \fIcommand as plugin\fR, prefix with \fB-!\fR - 4. To skip user confirmation after command execution, suffix with \fB*\fR + 5. To skip user confirmation after command execution, suffix with \fB*\fR Note: Do not use \fB*\fR with programs those run and exit e.g. cat export NNN_PLUG='y:-!sync*' - 5. To run a \fIGUI app as plugin\fR, add a \fB&\fR after \fB!\fR + 6. To run a \fIGUI app as plugin\fR, add a \fB&\fR after \fB!\fR Note: \fI$nnn\fR must be the last argument in this case. export NNN_PLUG='m:-!&mousepad $nnn' - 6. To show the output of run-and-exit commands which do not need user input, + 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) diff --git a/plugins/README.md b/plugins/README.md index c13bf10ee6877aa98387a8c2ca41fda08c676594..b272eb54c5d22eee80cd2a4dec369bf1b3baa64a 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -183,8 +183,9 @@ 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 `-!` +2. `$nnn` must be the last argument (if used) to run a _command as plugin_ +3. (_Again_) add `!` before the command +4. To disable directory refresh after running a _command as plugin_, prefix with `-!` #### Some useful key-command examples diff --git a/src/nnn.c b/src/nnn.c index d47e47a90baa4577ce7a5c5b36a932c320a3c66c..46daf97422eb37e2987103af935214bf80649375 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -5142,7 +5142,7 @@ } setenv("NNN_INCLUDE_HIDDEN", xitoa(cfg.showhidden), 1); } -static bool run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags) +static void run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags) { size_t len; @@ -5155,18 +5155,18 @@ g_buf[len - 1] = '\0'; /* Get rid of trailing no confirmation symbol */ --len; } - if (flags & F_PAGE) - get_output(g_buf, NULL, NULL, -1, TRUE, TRUE); - else if (flags & F_NOTRACE) { + if ((flags & F_PAGE) || (flags & F_NOTRACE)) { if (is_suffix(g_buf, " $nnn")) g_buf[len - 5] = '\0'; else runfile = NULL; - spawn(g_buf, runfile, NULL, NULL, flags); + + if (flags & F_PAGE) + get_output(g_buf, runfile, NULL, -1, TRUE, TRUE); + else // F_NOTRACE + spawn(g_buf, runfile, NULL, NULL, flags); } else spawn(utils[UTIL_SH_EXEC], g_buf, NULL, NULL, flags); - - return TRUE; } static bool plctrl_init(void) @@ -5296,8 +5296,10 @@ if (!*file) return FALSE; - if ((flags & F_NOTRACE) || (flags & F_PAGE)) - return run_cmd_as_plugin(file, runfile, flags); + if ((flags & F_NOTRACE) || (flags & F_PAGE)) { + run_cmd_as_plugin(file, runfile, flags); + return TRUE; + } cmd_as_plugin = TRUE; } @@ -5331,7 +5333,7 @@ spawn(g_buf, *lastname, *path, sel, 0); } else spawn(g_buf, NULL, *path, sel, 0); } else - run_cmd_as_plugin(file, NULL, flags); + run_cmd_as_plugin(file, runfile, flags); close(wfd); _exit(EXIT_SUCCESS);