aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-09-28 15:18:09 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-09-28 16:33:22 +0530
commite80b9b3c6a2a91165ba77972452dca9de752d3c6 (patch)
treea104a65a92b09aac1656650229504f63e129b4c9 /src
parentdc9245d6b02eb106693623706ebd2fdd71ad0f93 (diff)
downloadnnn-e80b9b3c6a2a91165ba77972452dca9de752d3c6.tar.gz
Export current entry name as NN
The current file or dir name is exported in env var NN before running a cmd at the command prompt or spawning a shell. Export current file name as NCUR
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 4e5ed59..17eec56 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -421,12 +421,14 @@ static const char * const env_cfg[] = {
#define VISUAL 1
#define EDITOR 2
#define PAGER 3
+#define NCUR 4
static const char * const envs[] = {
"SHELL",
"VISUAL",
"EDITOR",
"PAGER",
+ "NN",
};
/* Event handling */
@@ -1113,6 +1115,12 @@ static int spawn(char *file, char *arg1, char *arg2, const char *dir, uchar flag
return retstatus;
}
+static void prompt_run(char *cmd, const char *cur, const char *path)
+{
+ setenv(envs[NCUR], cur, 1);
+ spawn(shell, "-c", cmd, path, F_CLI | F_CMD);
+}
+
/* Get program name from env var, else return fallback program */
static char *xgetenv(const char *name, char *fallback)
{
@@ -1739,7 +1747,7 @@ static int filterentries(char *path)
/* If there's a filter, try a command on ^P */
if (cfg.filtercmd && *ch == CONTROL('P') && len > 1) {
- spawn(shell, "-c", pln, path, F_CLI | F_CMD);
+ prompt_run(pln, (ndents ? dents[cur].name : ""), path);
continue;
}
@@ -4407,6 +4415,7 @@ nochange:
goto nochange;
break;
case SEL_SHELL:
+ setenv(envs[NCUR], (ndents ? dents[cur].name : ""), 1);
spawn(shell, NULL, NULL, path, F_CLI);
break;
case SEL_PLUGKEY: // fallthrough
@@ -4490,7 +4499,7 @@ nochange:
}
#endif
if (tmp && tmp[0]) // NOLINT
- spawn(shell, "-c", tmp, path, F_CLI | F_CMD);
+ prompt_run(tmp, (ndents ? dents[cur].name : ""), path);
}
/* Continue in navigate-as-you-type mode, if enabled */