]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix build break
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 25 Aug 2021 14:25:48 +0000 (19:55 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 25 Aug 2021 14:44:55 +0000 (20:14 +0530)
plugins/README.md
src/nnn.c

index bcd01cabfaf077702d7751a38e85d418b6708188..b2b43f6a230bc6459f4685f4af993d65a2d51298 100644 (file)
@@ -206,6 +206,7 @@ When `nnn` executes a plugin, it does the following:
     2. `$2`: The working directory (might differ from `$PWD` in case of symlinked paths; non-canonical).
     3. `$3`: The picker mode output file (`-` for stdout) if `nnn` is executed as a file picker.
 - Sets the environment variable `NNN_PIPE` used to control `nnn` active directory.
+- Exports the [special variables](https://github.com/jarun/nnn/wiki/Concepts#special-variables).
 
 Plugins can also read the `.selection` file in the config directory.
 
index 0d250712f26519cd2bbcd42a06177201887cab95..146acbbbe492c0062200f7fbc3426fec6f6a7406 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -5051,6 +5051,30 @@ static void show_help(const char *path)
        unlink(g_tmpfpath);
 }
 
+static void setexports(void)
+{
+       char dvar[] = "d0";
+       char fvar[] = "f0";
+
+       if (ndents) {
+               setenv(envs[ENV_NCUR], pdents[cur].name, 1);
+               xstrsncpy(g_ctx[cfg.curctx].c_name, pdents[cur].name, NAME_MAX + 1);
+       } else if (g_ctx[cfg.curctx].c_name[0])
+               g_ctx[cfg.curctx].c_name[0] = '\0';
+
+       for (uchar_t i = 0; i < CTX_MAX; ++i) {
+               if (g_ctx[i].c_cfg.ctxactive) {
+                       dvar[1] = fvar[1] = '1' + i;
+                       setenv(dvar, g_ctx[i].c_path, 1);
+
+                       if (g_ctx[i].c_name[0]) {
+                               mkpath(g_ctx[i].c_path, g_ctx[i].c_name, g_buf);
+                               setenv(fvar, g_buf, 1);
+                       }
+               }
+       }
+}
+
 static bool run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
 {
        size_t len;
@@ -5186,6 +5210,8 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last
                g_state.pluginit = 1;
        }
 
+       setexports();
+
        /* Check for run-cmd-as-plugin mode */
        if (*file == '!') {
                flags = F_MULTI | F_CONFIRM;
@@ -5310,30 +5336,6 @@ static bool prompt_run(void)
        return ret;
 }
 
-static void setexports(char *buf)
-{
-       char dvar[] = "d0";
-       char fvar[] = "f0";
-
-       if (ndents) {
-               setenv(envs[ENV_NCUR], pdents[cur].name, 1);
-               xstrsncpy(g_ctx[cfg.curctx].c_name, pdents[cur].name, NAME_MAX + 1);
-       } else if (g_ctx[cfg.curctx].c_name[0])
-               g_ctx[cfg.curctx].c_name[0] = '\0';
-
-       for (uchar_t i = 0; i < CTX_MAX; ++i) {
-               if (g_ctx[i].c_cfg.ctxactive) {
-                       dvar[1] = fvar[1] = '1' + i;
-                       setenv(dvar, g_ctx[i].c_path, 1);
-
-                       if (g_ctx[i].c_name[0]) {
-                               mkpath(g_ctx[i].c_path, g_ctx[i].c_name, buf);
-                               setenv(fvar, buf, 1);
-                       }
-               }
-       }
-}
-
 static bool handle_cmd(enum action sel, char *newpath)
 {
        endselection(FALSE);
@@ -5341,7 +5343,7 @@ static bool handle_cmd(enum action sel, char *newpath)
        if (sel == SEL_LAUNCH)
                return launch_app(newpath);
 
-       setexports(newpath);
+       setexports();
 
        if (sel == SEL_PROMPT)
                return prompt_run();
@@ -6800,8 +6802,6 @@ nochange:
                                        rundir[0] = '\0';
                                        clearfilter();
 
-                                       setexports(newpath);
-
                                        if (chdir(path) == -1
                                            || !run_plugin(&path, pent->name,
                                                                    runfile, &lastname, &lastdir)) {
@@ -7536,8 +7536,6 @@ nochange:
                                } else
                                        r = TRUE;
 
-                               setexports(newpath);
-
                                if (!run_plugin(&path, tmp, (ndents ? pdents[cur].name : NULL),
                                                         &lastname, &lastdir)) {
                                        printwait(messages[MSG_FAILED], &presel);