mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
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
This commit is contained in:
parent
dc9245d6b0
commit
e80b9b3c6a
|
@ -21,6 +21,7 @@
|
||||||
## Index
|
## Index
|
||||||
|
|
||||||
- [Introduction](#introduction)
|
- [Introduction](#introduction)
|
||||||
|
- [Wiki, resources](#wiki-resources)
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
- [Quickstart](#quickstart)
|
- [Quickstart](#quickstart)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
|
@ -49,9 +50,9 @@ If you prefer a lightweight system or productivity-boosting utilities, `nnn` is
|
||||||
|
|
||||||
It runs smoothly on the Raspberry Pi, Termux on Android, Linux, macOS, BSD, Cygwin and Linux subsystem for Windows. `nnn` works seamlessly with DEs and GUI utilities.
|
It runs smoothly on the Raspberry Pi, Termux on Android, Linux, macOS, BSD, Cygwin and Linux subsystem for Windows. `nnn` works seamlessly with DEs and GUI utilities.
|
||||||
|
|
||||||
#### Important links
|
## Wiki, resources
|
||||||
|
|
||||||
1. [Wiki](https://github.com/jarun/nnn/wiki): operational concepts, how tos, use cases, chronology and insights
|
1. [Wiki](https://github.com/jarun/nnn/wiki) (concepts, how-tos, use cases, chronology and insights)
|
||||||
2. [Performance numbers](https://github.com/jarun/nnn/wiki/Performance)
|
2. [Performance numbers](https://github.com/jarun/nnn/wiki/Performance)
|
||||||
3. [Plugin repository and docs](https://github.com/jarun/nnn/tree/master/plugins)
|
3. [Plugin repository and docs](https://github.com/jarun/nnn/tree/master/plugins)
|
||||||
4. [(neo)vim plugin](https://github.com/mcchrish/nnn.vim)
|
4. [(neo)vim plugin](https://github.com/mcchrish/nnn.vim)
|
||||||
|
|
13
src/nnn.c
13
src/nnn.c
|
@ -421,12 +421,14 @@ static const char * const env_cfg[] = {
|
||||||
#define VISUAL 1
|
#define VISUAL 1
|
||||||
#define EDITOR 2
|
#define EDITOR 2
|
||||||
#define PAGER 3
|
#define PAGER 3
|
||||||
|
#define NCUR 4
|
||||||
|
|
||||||
static const char * const envs[] = {
|
static const char * const envs[] = {
|
||||||
"SHELL",
|
"SHELL",
|
||||||
"VISUAL",
|
"VISUAL",
|
||||||
"EDITOR",
|
"EDITOR",
|
||||||
"PAGER",
|
"PAGER",
|
||||||
|
"NN",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Event handling */
|
/* Event handling */
|
||||||
|
@ -1113,6 +1115,12 @@ static int spawn(char *file, char *arg1, char *arg2, const char *dir, uchar flag
|
||||||
return retstatus;
|
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 */
|
/* Get program name from env var, else return fallback program */
|
||||||
static char *xgetenv(const char *name, char *fallback)
|
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 there's a filter, try a command on ^P */
|
||||||
if (cfg.filtercmd && *ch == CONTROL('P') && len > 1) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4407,6 +4415,7 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
break;
|
break;
|
||||||
case SEL_SHELL:
|
case SEL_SHELL:
|
||||||
|
setenv(envs[NCUR], (ndents ? dents[cur].name : ""), 1);
|
||||||
spawn(shell, NULL, NULL, path, F_CLI);
|
spawn(shell, NULL, NULL, path, F_CLI);
|
||||||
break;
|
break;
|
||||||
case SEL_PLUGKEY: // fallthrough
|
case SEL_PLUGKEY: // fallthrough
|
||||||
|
@ -4490,7 +4499,7 @@ nochange:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (tmp && tmp[0]) // NOLINT
|
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 */
|
/* Continue in navigate-as-you-type mode, if enabled */
|
||||||
|
|
Loading…
Reference in a new issue