From 1e182a1fe5f7141b893833b1666ffe299c6621cb Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 17 Jul 2021 13:47:08 +0530 Subject: [PATCH] Remember the last command executed at prompt --- src/nnn.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/nnn.c b/src/nnn.c index f103eb78..4fadf59d 100644 --- 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