diff --git a/man/hh.1 b/man/hh.1 index 9a80817..9a5bd9e 100644 --- a/man/hh.1 +++ b/man/hh.1 @@ -122,6 +122,9 @@ Configuration options: \fIduplicates\fR Show duplicates in rawhistory (duplicates are discarded by default). +\fIverbose-kill\fR + Print the last command command deleted from history (nothing is printed by default). + \fIblacklist\fR Load list of commands to skip when processing history from ~/.hh_blacklist (built-in blacklist used otherwise). diff --git a/src/hstr.c b/src/hstr.c index a704ca4..bc77a60 100644 --- a/src/hstr.c +++ b/src/hstr.c @@ -97,19 +97,19 @@ #define HH_CONFIG_THEME_MONOCHROMATIC "monochromatic" #define HH_CONFIG_THEME_HICOLOR "hicolor" -#define HH_CONFIG_CASE "casesensitive" -#define HH_CONFIG_REGEXP "regexp" -#define HH_CONFIG_SUBSTRING "substring" -#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_CASE "casesensitive" +#define HH_CONFIG_REGEXP "regexp" +#define HH_CONFIG_SUBSTRING "substring" +#define HH_CONFIG_KEYWORDS "keywords" +#define HH_CONFIG_SORTING "rawhistory" +#define HH_CONFIG_FAVORITES "favorites" +#define HH_CONFIG_NOCONFIRM "noconfirm" +#define HH_CONFIG_VERBOSE_KILL "verbose-kill" #define HH_CONFIG_PROMPT_BOTTOM "prompt-bottom" -#define HH_CONFIG_BLACKLIST "blacklist" -#define HH_CONFIG_KEEP_PAGE "keep-page" -#define HH_CONFIG_DEBUG "debug" -#define HH_CONFIG_WARN "warning" +#define HH_CONFIG_BLACKLIST "blacklist" +#define HH_CONFIG_KEEP_PAGE "keep-page" +#define HH_CONFIG_DEBUG "debug" +#define HH_CONFIG_WARN "warning" #define HH_CONFIG_BIG_KEYS_SKIP "big-keys-skip" #define HH_CONFIG_BIG_KEYS_FLOOR "big-keys-floor" #define HH_CONFIG_BIG_KEYS_EXIT "big-keys-exit" @@ -222,7 +222,7 @@ static const char *INSTALL_ZSH_STRING= "\nexport HISTFILE=~/.zsh_history # ensure history file visibility" "\nexport HH_CONFIG=hicolor # get more colors" "\nbindkey -s \"\\C-r\" \"\\eqhh\\n\" # bind hh to Ctrl-r (for Vi mode check doc)" - // TODO try variant with arg/pars separation + // TODO try variant with args/pars separation //"\nbindkey -s \"\\C-r\" \"\\eqhh --\\n\" # bind hh to Ctrl-r (for Vi mode check doc)" // alternate binding options in zsh: // bindkey -s '^R' '^Ahh ^M' @@ -288,6 +288,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 + bool verboseKill; // write a message on delete of the last command in history int bigKeys; int debugLevel; @@ -391,6 +392,9 @@ void hstr_get_env_configuration(Hstr *hstr) hstr->bigKeys=RADIX_BIG_KEYS_SKIP; } } + if(strstr(hstr_config,HH_CONFIG_VERBOSE_KILL)) { + hstr->verboseKill=true; + } if(strstr(hstr_config,HH_CONFIG_BLACKLIST)) { hstr->blacklist.useFile=true; } @@ -1429,7 +1433,7 @@ void hstr_getopt(int argc, char **argv, Hstr *hstr) hstr->interactive=false; break; case 'k': - if(history_mgmt_remove_last_history_entry()) { + if(history_mgmt_remove_last_history_entry(hstr->verboseKill)) { exit(EXIT_SUCCESS); } else { exit(EXIT_FAILURE); diff --git a/src/hstr_history.c b/src/hstr_history.c index 3c1280f..a01e66e 100644 --- a/src/hstr_history.c +++ b/src/hstr_history.c @@ -263,7 +263,7 @@ int history_mgmt_remove_from_system_history(char *cmd) return occurences; } -bool history_mgmt_remove_last_history_entry() +bool history_mgmt_remove_last_history_entry(bool verbose) { using_history(); @@ -276,11 +276,17 @@ bool history_mgmt_remove_last_history_entry() // delete the last command + the command that was used to run HSTR if(historyState->length > 1) { // length is NOT updated on history entry removal + if(verbose) { + fprintf(stdout, "Deleting command '%s' from history\n", historyState->entries[historyState->length-2]->line); + } free_history_entry(remove_history(historyState->length-1)); free_history_entry(remove_history(historyState->length-2)); write_history(get_history_file_name()); return true; } + if(verbose) { + fprintf(stderr, "Unable to delete the last command from history.\n"); + } return false; } diff --git a/src/include/hstr_history.h b/src/include/hstr_history.h index 34c82e4..d7a4a87 100644 --- a/src/include/hstr_history.h +++ b/src/include/hstr_history.h @@ -60,7 +60,7 @@ void free_prioritized_history(void); void history_mgmt_open(void); void history_clear_dirty(void); int history_mgmt_remove_from_system_history(char *cmd); -bool history_mgmt_remove_last_history_entry(); +bool history_mgmt_remove_last_history_entry(bool verbose); int history_mgmt_remove_from_raw(char *cmd, HistoryItems *history); int history_mgmt_remove_from_ranked(char *cmd, HistoryItems *history); void history_mgmt_flush(void);