commit 1e182a1fe5f7141b893833b1666ffe299c6621cb
parent f7aa4ed32456c7416383b9ce42a257af375faa0a
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date: Sat, 17 Jul 2021 13:47:08 +0530
Remember the last command executed at prompt
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/nnn.c b/src/nnn.c
@@ -445,6 +445,7 @@ static char *mark;
#ifndef NOFIFO
static char *fifopath;
#endif
+static char *lastcmd;
static ullong_t *ihashbmp;
static struct entry *pdents;
static blkcnt_t dir_blocks;
@@ -3553,6 +3554,12 @@ static char *xreadline(const char *prefill, const char *prompt)
case KEY_HOME:
pos = 0;
break;
+ case KEY_UP: // fallthrough
+ case KEY_DOWN:
+ if (prompt && lastcmd && (xstrcmp(prompt, PROMPT) == 0)) {
+ printmsg(prompt);
+ len = pos = mbstowcs(buf, lastcmd, READLINE_MAX); // fallthrough
+ }
default:
break;
}
@@ -5213,6 +5220,8 @@ static bool prompt_run(const char *current)
tmp = getreadline("\n"PROMPT);
#endif
if (tmp && *tmp) { // NOLINT
+ free(lastcmd);
+ lastcmd = xstrdup(tmp);
ret = TRUE;
spawn(shell, "-c", tmp, NULL, F_CLI | F_CONFIRM);
} else