From 378f6684be1129a181ef3644da5bc52a54c0923e 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/5] 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 | 31 ++++++++++++++++++++++++++----- src/global.c | 4 ++++ src/nano.c | 3 +++ src/proto.h | 1 + 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/files.c b/src/files.c index 6a6bb1ca..d4a9a934 100644 --- a/src/files.c +++ b/src/files.c @@ -1039,6 +1039,7 @@ void do_insertfile(void) { int i; const char *msg; + char *buf; char *given = mallocstrcpy(NULL, ""); /* The last answer the user typed at the statusbar prompt. */ #ifndef NANO_TINY @@ -1069,6 +1070,18 @@ void do_insertfile(void) msg = _("File to insert [from %s]"); } + /* We display the command prompt below. */ + if (execute && *last_command != '\0') { + char *disp = display_string(last_command, 0, COLS / 3, FALSE); + + buf = charalloc(strlen(disp) + strlen(msg) + 7); + /* We use (COLS / 3) here because we need to see more on the line. */ + sprintf(buf, "%s [%s%s]", msg, disp, + (strlenpt(last_search) > COLS / 3) ? "..." : ""); + free(disp); + } else + buf = mallocstrcpy(NULL, msg); + present_path = mallocstrcpy(present_path, "./"); i = do_prompt(TRUE, TRUE, @@ -1079,15 +1092,18 @@ void do_insertfile(void) #ifndef DISABLE_HISTORIES NULL, #endif - edit_refresh, msg, + edit_refresh, buf, #ifndef DISABLE_OPERATINGDIR operating_dir != NULL ? operating_dir : #endif "./"); - /* If we're in multibuffer mode and the filename or command is + /* Release buf now that we don't need it anymore. */ + free(buf); + + /* 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 && *last_command == '\0') || (!execute && i == -2 && !ISSET(MULTIBUFFER))) { statusbar(_("Cancelled")); break; } else { @@ -1128,7 +1144,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 +1155,12 @@ void do_insertfile(void) open_buffer("", FALSE); #endif /* Save the command's output in the current buffer. */ - execute_command(answer); + if (*answer != '\0') { + execute_command(answer); + last_command = mallocstrcpy(last_command, 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 e2017115..88983530 100644 --- a/src/global.c +++ b/src/global.c @@ -93,6 +93,9 @@ 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. */ @@ -1760,6 +1763,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/nano.c b/src/nano.c index f29cea90..9012dee3 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2464,6 +2464,9 @@ int main(int argc, char **argv) /* Initialize the search string. */ last_search = mallocstrcpy(NULL, ""); + /* Initialize the command string. */ + last_command = mallocstrcpy(NULL, ""); + /* If tabsize wasn't specified, set its default value. */ if (tabsize == -1) tabsize = WIDTH_OF_TAB; diff --git a/src/proto.h b/src/proto.h index 8ee4eb0e..4abc453b 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.11.0