mirror of
https://github.com/dvorka/hstr.git
synced 2024-09-20 14:56:14 +08:00
Adding verbose option for kill last command #251.
This commit is contained in:
parent
c0c6db116a
commit
5cd7e1548b
3
man/hh.1
3
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).
|
||||
|
||||
|
|
10
src/hstr.c
10
src/hstr.c
|
@ -104,7 +104,7 @@
|
|||
#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_VERBOSE_KILL "verbose-kill"
|
||||
#define HH_CONFIG_PROMPT_BOTTOM "prompt-bottom"
|
||||
#define HH_CONFIG_BLACKLIST "blacklist"
|
||||
#define HH_CONFIG_KEEP_PAGE "keep-page"
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue