From 5b671988eeabc35318f89538b5b7cf28a9dc0ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Fri, 1 Sep 2017 14:59:57 -0300 Subject: [PATCH] Remeber 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 ++++++++++++++++----- src/global.c | 3 +++ src/proto.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/files.c b/src/files.c index 105db52..54cf3f6 100644 --- a/src/files.c +++ b/src/files.c @@ -1042,6 +1042,7 @@ void do_insertfile(void) { int i; const char *msg; + char *prompt; char *given = mallocstrcpy(NULL, ""); /* The last answer the user typed at the statusbar prompt. */ #ifndef NANO_TINY @@ -1072,6 +1073,10 @@ void do_insertfile(void) msg = _("File to insert [from %s]"); } + if(!execute || last_command == NULL || asprintf(&prompt, "%s [%s]", msg, last_command) == -1) + prompt = (char*)msg; + + present_path = mallocstrcpy(present_path, "./"); i = do_prompt(TRUE, TRUE, @@ -1082,15 +1087,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 (!execute && (i == -1 || (i == -2 && !ISSET(MULTIBUFFER)))) { statusbar(_("Cancelled")); break; } else { @@ -1131,7 +1136,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 @@ -1142,7 +1147,13 @@ void do_insertfile(void) open_buffer("", FALSE); #endif /* Save the command's output in the current buffer. */ - execute_command(answer); + if (strcmp(answer, "") !=0) { + execute_command(answer); + free(last_command); + last_command = strdup(answer); + } else { + execute_command(last_command); + } #ifdef ENABLE_MULTIBUFFER /* If this is a new buffer, put the cursor at the top. */ diff --git a/src/global.c b/src/global.c index 7c90b40..61c81f1 100644 --- a/src/global.c +++ b/src/global.c @@ -92,6 +92,8 @@ ssize_t wrap_at = -CHARS_FROM_EOL; char *last_search = NULL; /* The last string we searched for. */ +char *last_command = NULL; + /* The last command we executed. */ char *present_path = NULL; /* The current browser directory when trying to do tab completion. */ @@ -1762,6 +1764,7 @@ void thanks_for_all_the_fish(void) #endif free(answer); free(last_search); + free(last_command); free(present_path); #ifndef DISABLE_SPELLER free(alt_speller); diff --git a/src/proto.h b/src/proto.h index 4fed496..c30edf2 100644 --- a/src/proto.h +++ b/src/proto.h @@ -87,6 +87,7 @@ extern ssize_t wrap_at; #endif extern char *last_search; +extern char *last_command; extern char *present_path; -- 2.7.4