From 85909ec588cdd6a85dd813e2f86208a45cbaac4c Mon Sep 17 00:00:00 2001 From: Martin Dvorak Date: Wed, 3 Jan 2018 12:40:20 +0100 Subject: [PATCH] Fixing bug #238 - delete confirmation can be disabled by env variable e.g. export HH_CONFIG=noconfirm --- man/hh.1 | 3 +++ src/hstr.c | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/man/hh.1 b/man/hh.1 index 856b077b..ff0f0a5f 100644 --- a/man/hh.1 +++ b/man/hh.1 @@ -95,6 +95,9 @@ Configuration options: \fIprompt-bottom\fR Show prompt at the bottom of the screen (default is prompt at the top). +\fInoconfirm\fR + Do not ask for confirmation on a history entry delete (default is with confirmation). + \fIregexp\fR Filter command history using regular expressions (substring match is default) diff --git a/src/hstr.c b/src/hstr.c index a1059d88..80b18d26 100644 --- a/src/hstr.c +++ b/src/hstr.c @@ -103,6 +103,7 @@ #define HH_CONFIG_KEYWORDS "keywords" #define HH_CONFIG_SORTING "rawhistory" #define HH_CONFIG_FAVORITES "favorites" +#define HH_CONFIG_NOCONFIRM "noconfirm" // MVP: model is the same regardless prompt is top or bottom - view is different #define HH_CONFIG_PROMPT_BOTTOM "prompt-bottom" #define HH_CONFIG_BLACKLIST "blacklist" @@ -274,6 +275,7 @@ typedef struct { unsigned char theme; bool keepPage; // do NOT clear page w/ selection on HH exit + bool noConfirm; // do NOT ask for confirmation on history entry delete int bigKeys; int debugLevel; @@ -383,6 +385,9 @@ void hstr_get_env_configuration(Hstr *hstr) if(strstr(hstr_config,HH_CONFIG_KEEP_PAGE)) { hstr->keepPage=true; } + if(strstr(hstr_config,HH_CONFIG_NOCONFIRM)) { + hstr->noConfirm=true; + } if(strstr(hstr_config,HH_CONFIG_DEBUG)) { hstr->debugLevel=HH_DEBUG_LEVEL_DEBUG; @@ -1057,9 +1062,11 @@ void loop_to_select(Hstr *hstr) msg=malloc(strlen(delete)+1); strcpy(msg,delete); - print_confirm_delete(msg, hstr); - cc = wgetch(stdscr); - if(cc == 'y') { + if(!hstr->noConfirm) { + print_confirm_delete(msg, hstr); + cc = wgetch(stdscr); + } + if(hstr->noConfirm || cc == 'y') { deletedOccurences=remove_from_history_model(msg, hstr); result=hstr_print_selection(maxHistoryItems, pattern, hstr); print_cmd_deleted_label(msg, deletedOccurences, hstr);