]> Sergey Matveev's repositories - nnn.git/commitdiff
More special variables at prompt/shell
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 24 Aug 2021 17:55:32 +0000 (23:25 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 24 Aug 2021 18:04:40 +0000 (23:34 +0530)
$dN: directory path open in context N
$fN: file path hovered in context N

README.md
src/nnn.c

index c7ca3941cbb93ed9a2355b752feebacc5cfc3049..52d8d3b50b085ff57e7a8e90ef42be57b1469f1b 100644 (file)
--- 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
index b96083ac95fe4deb58865eb8cd2c4a439db4e0a8..94fe6bd08b040b0f88cea7e3ffe48e960eafcd0d 100644 (file)
--- 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)