From cd33acbd515e7b101982fa5bd10ba33ec01b5f37 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 14 Jun 2017 17:31:57 +0200 Subject: [PATCH] Implement !- and !-* commands to clear command history --- libr/cons/dietline.c | 8 ++++++-- libr/core/cmd.c | 8 ++++++++ libr/core/file.c | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libr/cons/dietline.c b/libr/cons/dietline.c index f268fb1a87..a52d174d52 100644 --- a/libr/cons/dietline.c +++ b/libr/cons/dietline.c @@ -80,7 +80,7 @@ static int r_line_readchar_utf8(unsigned char *s, int slen) { } s[len] = r_cons_controlz (s[len]); if (!s[len]) { - return 1; // ^z + return 1; // ^z } if (s[len] < 28) { return s[0]? 1: 0; @@ -100,8 +100,9 @@ static int r_line_readchar_utf8(unsigned char *s, int slen) { return len; } #endif + #if __WINDOWS__ && !__CYGWIN__ -static int r_line_readchar_win(int *vch) { // this function handle the input in console mode +static int r_line_readchar_win(int *vch) { // this function handle the input in console mode INPUT_RECORD irInBuf[128]; BOOL ret, bCtrl = FALSE; DWORD mode, out; @@ -351,6 +352,9 @@ R_API int r_line_hist_load(const char *file) { R_API int r_line_hist_save(const char *file) { FILE *fd; int i, ret = false; + if (!file || !*file) { + return false; + } char *p, *path = r_str_home (file); if (path != NULL) { p = (char *) r_str_lastbut (path, R_SYS_DIR[0], NULL); // TODO: use fs diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 02e229711c..47bd8e055b 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -1135,6 +1135,14 @@ static int cmd_system(void *data, const char *input) { ut64 n; int ret = 0; switch (*input) { + case '-': + if (input[1]) { + r_line_hist_free(); + r_line_hist_save (R2_HOMEDIR"/history"); + } else { + r_line_hist_free(); + } + break; case '=': if (input[1] == '?') { r_cons_printf ("Usage: !=[!] - enable/disable remote commands\n"); diff --git a/libr/core/file.c b/libr/core/file.c index 611c0e8bc2..b3b98701d9 100644 --- a/libr/core/file.c +++ b/libr/core/file.c @@ -184,6 +184,8 @@ R_API void r_core_sysenv_help(const RCore *core) { "!!", "ls~txt", "print output of 'ls' and grep for 'txt'", ".!", "rabin2 -rpsei ${FILE}", "run each output line as a r2 cmd", "!", "echo $SIZE", "display file size", + "!-", "", "clear history in current session", + "!-*", "", "clear and save empty history log", "!=!", "", "enable remotecmd mode", "=!=", "", "disable remotecmd mode", "\nEnvironment:", "", "",