xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit 5cd7e1548b826b5ea43d67e78731d1d245a7dab8

Adding verbose option for kill last command #251.
Author: Martin Dvorak
Author date (UTC): 2018-02-21 07:40
Committer name: Martin Dvorak
Committer date (UTC): 2018-02-21 07:40
Parent(s): c0c6db116aa3c9557c0f94892114fe28cabd6a65
Signing key:
Tree: b113c460407ced27278ee62c41fe7563c821325c
File Lines added Lines deleted
man/hh.1 3 0
src/hstr.c 18 14
src/hstr_history.c 7 1
src/include/hstr_history.h 1 1
File man/hh.1 changed (mode: 100644) (index 9a80817..9a5bd9e)
... ... Configuration options:
122 122 \fIduplicates\fR \fIduplicates\fR
123 123 Show duplicates in rawhistory (duplicates are discarded by default). Show duplicates in rawhistory (duplicates are discarded by default).
124 124
125 \fIverbose-kill\fR
126 Print the last command command deleted from history (nothing is printed by default).
127
125 128 \fIblacklist\fR \fIblacklist\fR
126 129 Load list of commands to skip when processing history from ~/.hh_blacklist (built-in blacklist used otherwise). Load list of commands to skip when processing history from ~/.hh_blacklist (built-in blacklist used otherwise).
127 130
File src/hstr.c changed (mode: 100644) (index a704ca4..bc77a60)
97 97
98 98 #define HH_CONFIG_THEME_MONOCHROMATIC "monochromatic" #define HH_CONFIG_THEME_MONOCHROMATIC "monochromatic"
99 99 #define HH_CONFIG_THEME_HICOLOR "hicolor" #define HH_CONFIG_THEME_HICOLOR "hicolor"
100 #define HH_CONFIG_CASE "casesensitive"
101 #define HH_CONFIG_REGEXP "regexp"
102 #define HH_CONFIG_SUBSTRING "substring"
103 #define HH_CONFIG_KEYWORDS "keywords"
104 #define HH_CONFIG_SORTING "rawhistory"
105 #define HH_CONFIG_FAVORITES "favorites"
106 #define HH_CONFIG_NOCONFIRM "noconfirm"
107 // MVP: model is the same regardless prompt is top or bottom - view is different
100 #define HH_CONFIG_CASE "casesensitive"
101 #define HH_CONFIG_REGEXP "regexp"
102 #define HH_CONFIG_SUBSTRING "substring"
103 #define HH_CONFIG_KEYWORDS "keywords"
104 #define HH_CONFIG_SORTING "rawhistory"
105 #define HH_CONFIG_FAVORITES "favorites"
106 #define HH_CONFIG_NOCONFIRM "noconfirm"
107 #define HH_CONFIG_VERBOSE_KILL "verbose-kill"
108 108 #define HH_CONFIG_PROMPT_BOTTOM "prompt-bottom" #define HH_CONFIG_PROMPT_BOTTOM "prompt-bottom"
109 #define HH_CONFIG_BLACKLIST "blacklist"
110 #define HH_CONFIG_KEEP_PAGE "keep-page"
111 #define HH_CONFIG_DEBUG "debug"
112 #define HH_CONFIG_WARN "warning"
109 #define HH_CONFIG_BLACKLIST "blacklist"
110 #define HH_CONFIG_KEEP_PAGE "keep-page"
111 #define HH_CONFIG_DEBUG "debug"
112 #define HH_CONFIG_WARN "warning"
113 113 #define HH_CONFIG_BIG_KEYS_SKIP "big-keys-skip" #define HH_CONFIG_BIG_KEYS_SKIP "big-keys-skip"
114 114 #define HH_CONFIG_BIG_KEYS_FLOOR "big-keys-floor" #define HH_CONFIG_BIG_KEYS_FLOOR "big-keys-floor"
115 115 #define HH_CONFIG_BIG_KEYS_EXIT "big-keys-exit" #define HH_CONFIG_BIG_KEYS_EXIT "big-keys-exit"
 
... ... static const char *INSTALL_ZSH_STRING=
222 222 "\nexport HISTFILE=~/.zsh_history # ensure history file visibility" "\nexport HISTFILE=~/.zsh_history # ensure history file visibility"
223 223 "\nexport HH_CONFIG=hicolor # get more colors" "\nexport HH_CONFIG=hicolor # get more colors"
224 224 "\nbindkey -s \"\\C-r\" \"\\eqhh\\n\" # bind hh to Ctrl-r (for Vi mode check doc)" "\nbindkey -s \"\\C-r\" \"\\eqhh\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
225 // TODO try variant with arg/pars separation
225 // TODO try variant with args/pars separation
226 226 //"\nbindkey -s \"\\C-r\" \"\\eqhh --\\n\" # bind hh to Ctrl-r (for Vi mode check doc)" //"\nbindkey -s \"\\C-r\" \"\\eqhh --\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
227 227 // alternate binding options in zsh: // alternate binding options in zsh:
228 228 // bindkey -s '^R' '^Ahh ^M' // bindkey -s '^R' '^Ahh ^M'
 
... ... typedef struct {
288 288 unsigned char theme; unsigned char theme;
289 289 bool keepPage; // do NOT clear page w/ selection on HH exit bool keepPage; // do NOT clear page w/ selection on HH exit
290 290 bool noConfirm; // do NOT ask for confirmation on history entry delete bool noConfirm; // do NOT ask for confirmation on history entry delete
291 bool verboseKill; // write a message on delete of the last command in history
291 292 int bigKeys; int bigKeys;
292 293 int debugLevel; int debugLevel;
293 294
 
... ... void hstr_get_env_configuration(Hstr *hstr)
391 392 hstr->bigKeys=RADIX_BIG_KEYS_SKIP; hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
392 393 } }
393 394 } }
395 if(strstr(hstr_config,HH_CONFIG_VERBOSE_KILL)) {
396 hstr->verboseKill=true;
397 }
394 398 if(strstr(hstr_config,HH_CONFIG_BLACKLIST)) { if(strstr(hstr_config,HH_CONFIG_BLACKLIST)) {
395 399 hstr->blacklist.useFile=true; hstr->blacklist.useFile=true;
396 400 } }
 
... ... void hstr_getopt(int argc, char **argv, Hstr *hstr)
1429 1433 hstr->interactive=false; hstr->interactive=false;
1430 1434 break; break;
1431 1435 case 'k': case 'k':
1432 if(history_mgmt_remove_last_history_entry()) {
1436 if(history_mgmt_remove_last_history_entry(hstr->verboseKill)) {
1433 1437 exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
1434 1438 } else { } else {
1435 1439 exit(EXIT_FAILURE); exit(EXIT_FAILURE);
File src/hstr_history.c changed (mode: 100644) (index 3c1280f..a01e66e)
... ... int history_mgmt_remove_from_system_history(char *cmd)
263 263 return occurences; return occurences;
264 264 } }
265 265
266 bool history_mgmt_remove_last_history_entry()
266 bool history_mgmt_remove_last_history_entry(bool verbose)
267 267 { {
268 268 using_history(); using_history();
269 269
 
... ... bool history_mgmt_remove_last_history_entry()
276 276 // delete the last command + the command that was used to run HSTR // delete the last command + the command that was used to run HSTR
277 277 if(historyState->length > 1) { if(historyState->length > 1) {
278 278 // length is NOT updated on history entry removal // length is NOT updated on history entry removal
279 if(verbose) {
280 fprintf(stdout, "Deleting command '%s' from history\n", historyState->entries[historyState->length-2]->line);
281 }
279 282 free_history_entry(remove_history(historyState->length-1)); free_history_entry(remove_history(historyState->length-1));
280 283 free_history_entry(remove_history(historyState->length-2)); free_history_entry(remove_history(historyState->length-2));
281 284 write_history(get_history_file_name()); write_history(get_history_file_name());
282 285 return true; return true;
283 286 } }
287 if(verbose) {
288 fprintf(stderr, "Unable to delete the last command from history.\n");
289 }
284 290 return false; return false;
285 291 } }
286 292
File src/include/hstr_history.h changed (mode: 100644) (index 34c82e4..d7a4a87)
... ... void free_prioritized_history(void);
60 60 void history_mgmt_open(void); void history_mgmt_open(void);
61 61 void history_clear_dirty(void); void history_clear_dirty(void);
62 62 int history_mgmt_remove_from_system_history(char *cmd); int history_mgmt_remove_from_system_history(char *cmd);
63 bool history_mgmt_remove_last_history_entry();
63 bool history_mgmt_remove_last_history_entry(bool verbose);
64 64 int history_mgmt_remove_from_raw(char *cmd, HistoryItems *history); int history_mgmt_remove_from_raw(char *cmd, HistoryItems *history);
65 65 int history_mgmt_remove_from_ranked(char *cmd, HistoryItems *history); int history_mgmt_remove_from_ranked(char *cmd, HistoryItems *history);
66 66 void history_mgmt_flush(void); void history_mgmt_flush(void);
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master