From db468ab9a13cc54e6425e1ed0fd9d3105aaf41b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Tue, 5 Sep 2017 22:45:00 -0300 Subject: [PATCH 1/4] Remember last executed command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Diego Aurélio Mesquita --- src/files.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/files.c b/src/files.c index 6a6bb1ca..c0ed8c17 100644 --- a/src/files.c +++ b/src/files.c @@ -1039,6 +1039,8 @@ void do_insertfile(void) { int i; const char *msg; + static char *lastcommand = NULL; + char *prompt; char *given = mallocstrcpy(NULL, ""); /* The last answer the user typed at the statusbar prompt. */ #ifndef NANO_TINY @@ -1069,6 +1071,9 @@ void do_insertfile(void) msg = _("File to insert [from %s]"); } + if (!execute || lastcommand == NULL || asprintf(&prompt, "%s [%s]", msg, lastcommand) == -1) + prompt = (char*)msg; + present_path = mallocstrcpy(present_path, "./"); i = do_prompt(TRUE, TRUE, @@ -1079,15 +1084,15 @@ void do_insertfile(void) #ifndef DISABLE_HISTORIES NULL, #endif - edit_refresh, msg, + edit_refresh, prompt, #ifndef DISABLE_OPERATINGDIR operating_dir != NULL ? operating_dir : #endif "./"); - /* If we're in multibuffer mode and the filename or command is + /* If we're in multibuffer mode and the filename is * blank, open a new buffer instead of canceling. */ - if (i == -1 || (i == -2 && !ISSET(MULTIBUFFER))) { + if (i == -1 || (i == -2 && lastcommand == NULL) || (!execute && i == -2 && !ISSET(MULTIBUFFER))) { statusbar(_("Cancelled")); break; } else { @@ -1128,7 +1133,7 @@ void do_insertfile(void) } #endif /* If we don't have a file yet, go back to the prompt. */ - if (i != 0 && (!ISSET(MULTIBUFFER) || i != -2)) + if (!execute && (i != 0 && (!ISSET(MULTIBUFFER) || i != -2))) continue; #ifndef NANO_TINY @@ -1139,7 +1144,13 @@ void do_insertfile(void) open_buffer("", FALSE); #endif /* Save the command's output in the current buffer. */ - execute_command(answer); + if (*answer != '\0') { + free(lastcommand); + execute_command(answer); + lastcommand = strdup(answer); + } else { + execute_command(lastcommand); + } #ifdef ENABLE_MULTIBUFFER /* If this is a new buffer, put the cursor at the top. */ -- 2.11.0