commit 900513710f3e71d62dd2d9d8635b2ce2210acdd4
parent 6243de06f4c5eee73d99d324fcd7aa0f35157cb6
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date: Tue, 24 Aug 2021 23:25:32 +0530
More special variables at prompt/shell
$dN: directory path open in context N
$fN: file path hovered in context N
Diffstat:
2 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
@@ -98,7 +98,7 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/embed/AbaauM7gUJw)
- Dir updates, notification on `cp`, `mv`, `rm` completion
- Copy file paths to system clipboard on select
- Launch apps, run commands, spawn a shell, toggle exe
- - Access hovered file at prompt or spawned shell
+ - Access context paths/files at prompt or spawned shell
- Lock terminal after configurable idle timeout
- Capture and show output of a program in help screen
- Basic support for screen readers and braille displays
diff --git a/src/nnn.c b/src/nnn.c
@@ -5276,14 +5276,12 @@ static bool launch_app(char *newpath)
return FALSE;
}
-/* Returns TRUE if at least command was run */
-static bool prompt_run(const char *current)
+/* Returns TRUE if at least one command was run */
+static bool prompt_run(void)
{
bool ret = FALSE;
char *tmp;
- setenv(envs[ENV_NCUR], current, 1);
-
while (1) {
#ifndef NORL
if (g_state.picker) {
@@ -5305,22 +5303,47 @@ static bool prompt_run(const char *current)
return ret;
}
-static bool handle_cmd(enum action sel, const char *current, char *newpath)
+static void setexports(char *buf)
{
- endselection(FALSE);
+ char dvar[] = "d0";
+ char fvar[] = "f0";
- if (sel == SEL_PROMPT)
- return prompt_run(current);
+ 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);
if (sel == SEL_LAUNCH)
return launch_app(newpath);
+ setexports(newpath);
+
+ if (sel == SEL_PROMPT)
+ return prompt_run();
+
/* Set nnn nesting level */
char *tmp = getenv(env_cfg[NNNLVL]);
int r = tmp ? atoi(tmp) : 0;
setenv(env_cfg[NNNLVL], xitoa(r + 1), 1);
- setenv(envs[ENV_NCUR], current, 1);
spawn(shell, NULL, NULL, NULL, F_CLI);
setenv(env_cfg[NNNLVL], xitoa(r), 1);
return TRUE;
@@ -7550,7 +7573,7 @@ nochange:
case SEL_SHELL: // fallthrough
case SEL_LAUNCH: // fallthrough
case SEL_PROMPT:
- r = handle_cmd(sel, (ndents ? pdents[cur].name : ""), newpath);
+ r = handle_cmd(sel, newpath);
/* Continue in type-to-nav mode, if enabled */
if (cfg.filtermode)