Skip to content

Commit

Permalink
Merge pull request #1783 from 7ocb/alternative-setenv-pwd-3
Browse files Browse the repository at this point in the history
Setting PWD: set on use case, not on browse
  • Loading branch information
jarun committed Dec 15, 2023
2 parents 82f9e54 + 3d2caf8 commit f2a8648
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion patches/restorepreview/mainline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ index 0388b23c..66d3316a 100644
case SEL_PROMPT:
+ if (g_state.previewer)
+ notify_fifo(FALSE, TRUE);
r = handle_cmd(sel, newpath);
r = handle_cmd(sel, path, newpath);
+ if (g_state.previewer) {
+ pkey = previewkey;
+ goto run_plugin;
Expand Down
13 changes: 6 additions & 7 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -5237,7 +5237,7 @@ static void show_help(const char *path)
unlink(g_tmpfpath);
}

static void setexports(void)
static void setexports(const char *path)
{
char dvar[] = "d0";
char fvar[] = "f0";
Expand All @@ -5261,6 +5261,7 @@ static void setexports(void)
}
setenv("NNN_INCLUDE_HIDDEN", xitoa(cfg.showhidden), 1);
setenv("NNN_PREFER_SELECTION", xitoa(cfg.prefersel), 1);
setenv("PWD", path, 1);
}

static void run_cmd_as_plugin(const char *file, uchar_t flags)
Expand Down Expand Up @@ -5391,7 +5392,7 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last
g_state.pluginit = 1;
}

setexports();
setexports(*path);

/* Check for run-cmd-as-plugin mode */
if (*file == '!') {
Expand Down Expand Up @@ -5565,14 +5566,14 @@ static bool prompt_run(void)
return ret;
}

static bool handle_cmd(enum action sel, char *newpath)
static bool handle_cmd(enum action sel, char *path, char *newpath)
{
endselection(FALSE);

if (sel == SEL_LAUNCH)
return launch_app(newpath);

setexports();
setexports(path);

if (sel == SEL_PROMPT)
return prompt_run();
Expand Down Expand Up @@ -6835,8 +6836,6 @@ static bool browse(char *ipath, const char *session, int pkey)
setdirwatch();
}

setenv("PWD", path, TRUE);

#ifndef NOX11
xterm_cfg(path);
#endif
Expand Down Expand Up @@ -7969,7 +7968,7 @@ static bool browse(char *ipath, const char *session, int pkey)
case SEL_SHELL: // fallthrough
case SEL_LAUNCH: // fallthrough
case SEL_PROMPT:
r = handle_cmd(sel, newpath);
r = handle_cmd(sel, path, newpath);

/* Continue in type-to-nav mode, if enabled */
if (cfg.filtermode)
Expand Down

0 comments on commit f2a8648

Please sign in to comment.