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 e3938d53c79d25886bb2718a5206e85accb42d13

Fixing #107 by making big keys handling in radix sort an option.
Author: Martin Dvorak
Author date (UTC): 2015-02-28 07:45
Committer name: Martin Dvorak
Committer date (UTC): 2015-02-28 07:45
Parent(s): 207bb1f6342beea415bc6a5594b2cc20296df2aa
Signing key:
Tree: 61876058f16a37f8b0a3b1fbbe058a30eaedf170
File Lines added Lines deleted
man/hh.1 17 5
src/hstr.c 16 2
src/hstr_history.c 2 2
src/include/hstr_history.h 1 1
src/include/radixsort.h 6 2
src/radixsort.c 3 4
File man/hh.1 changed (mode: 100644) (index 6d4fccd..ec1917c)
... ... Toggle regular expression and substring search.
41 41 Toggle case sensitive search. Toggle case sensitive search.
42 42 .TP .TP
43 43 \fBCtrl\-/\fR, \fBCtrl\-7\fR \fBCtrl\-/\fR, \fBCtrl\-7\fR
44 Rotate view of history as provided by BASH, ranked history ordered by the number of occurences/length/timestamp and favorites.
44 Rotate view of history as provided by Bash, ranked history ordered by the number of occurences/length/timestamp and favorites.
45 45 .TP .TP
46 46 \fBCtrl\-f\fR \fBCtrl\-f\fR
47 47 Add currently selected command to favorites. Add currently selected command to favorites.
 
... ... Navigate in the history list.
56 56 Choose currently selected item for completion and let user to edit it on the command prompt. Choose currently selected item for completion and let user to edit it on the command prompt.
57 57 .TP .TP
58 58 \fBLEFT\fR arrow \fBLEFT\fR arrow
59 Choose currently selected item for completion and let user to edit it editor (fix command).
59 Choose currently selected item for completion and let user to edit it in editor (fix command).
60 60 .TP .TP
61 61 \fBENTER\fR \fBENTER\fR
62 62 Choose currently selected item for completion and execute it. Choose currently selected item for completion and execute it.
 
... ... Configuration options:
85 85 Get more colors with this option (default is monochromatic). Get more colors with this option (default is monochromatic).
86 86
87 87 \fImonochromatic\fR \fImonochromatic\fR
88 Ensure black and white view with this option.
88 Ensure black and white view.
89 89
90 90 \fIregexp\fR \fIregexp\fR
91 91 Filter command history using regular expressions (substring match is default) Filter command history using regular expressions (substring match is default)
 
... ... Configuration options:
105 105 \fIfavorites\fR \fIfavorites\fR
106 106 Show favorites as a default view (metric-based view is shown otherwise). Show favorites as a default view (metric-based view is shown otherwise).
107 107
108 \fIbigkeysskip\fR
109 Skip big history entries i.e. very long lines (default).
110
111 \fIbigkeysfloor\fR
112 Use different sorting slot for big keys when building metrics-based view (big keys are skipped by default).
113
114 \fIbigkeysexit\fR
115 Exit (fail) on presence of a big key in history (big keys are skipped by default).
116
108 117 \fIwarning\fR \fIwarning\fR
109 118 Show warning. Show warning.
110 119
 
... ... bindkey -s "\eC\-r" "\eeqhh\en" # bind hh to Ctrl-r (for Vi mode check doc)
151 160 .fi .fi
152 161 .SH EXAMPLES .SH EXAMPLES
153 162 .TP .TP
163 \fBhh git\fR
164 Start `hh` and show only history items containing 'git'.
165 .TP
154 166 \fBhh --non-interactive git\fR \fBhh --non-interactive git\fR
155 Print history items containing 'git' to standard output and exit.
167 Print history items containing 'git' to standard output and exit.
156 168 .TP .TP
157 169 \fBhh --show-configuration >> ~/.bashrc\fR \fBhh --show-configuration >> ~/.bashrc\fR
158 Append default \fBhh\fR configuration to your Bash profile.
170 Append default \fBhh\fR configuration to your Bash profile.
159 171 .SH AUTHOR .SH AUTHOR
160 172 Written by Martin Dvorak <martin.dvorak@mindforger.com> Written by Martin Dvorak <martin.dvorak@mindforger.com>
161 173 .SH BUGS .SH BUGS
File src/hstr.c changed (mode: 100644) (index bf15069..6f1e864)
93 93 #define HH_CONFIG_FAVORITES "favorites" #define HH_CONFIG_FAVORITES "favorites"
94 94 #define HH_CONFIG_DEBUG "debug" #define HH_CONFIG_DEBUG "debug"
95 95 #define HH_CONFIG_WARN "warning" #define HH_CONFIG_WARN "warning"
96 #define HH_CONFIG_BIG_KEYS_SKIP "bigkeysskip"
97 #define HH_CONFIG_BIG_KEYS_FLOOR "bigkeysfloor"
98 #define HH_CONFIG_BIG_KEYS_EXIT "bigkeysexit"
96 99
97 100 #define HH_DEBUG_LEVEL_NONE 0 #define HH_DEBUG_LEVEL_NONE 0
98 101 #define HH_DEBUG_LEVEL_WARN 1 #define HH_DEBUG_LEVEL_WARN 1
 
... ... typedef struct {
239 242 bool interactive; bool interactive;
240 243
241 244 bool hicolor; bool hicolor;
245 int bigKeys;
242 246 int debugLevel; int debugLevel;
243 247
244 248 HstrRegexp regexp; HstrRegexp regexp;
 
... ... void hstr_init(Hstr *hstr)
261 265 hstr->interactive=true; hstr->interactive=true;
262 266
263 267 hstr->hicolor=FALSE; hstr->hicolor=FALSE;
264
268 hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
265 269 hstr->debugLevel=HH_DEBUG_LEVEL_NONE; hstr->debugLevel=HH_DEBUG_LEVEL_NONE;
270
266 271 hstr->cmdline[0]=0; hstr->cmdline[0]=0;
267 272 hstr_regexp_init(&hstr->regexp); hstr_regexp_init(&hstr->regexp);
268 273 } }
 
... ... void hstr_get_env_configuration(Hstr *hstr)
295 300 hstr->historyView=HH_VIEW_FAVORITES; hstr->historyView=HH_VIEW_FAVORITES;
296 301 } }
297 302 } }
303 if(strstr(hstr_config,HH_CONFIG_BIG_KEYS_EXIT)) {
304 hstr->bigKeys=RADIX_BIG_KEYS_EXIT;
305 } else {
306 if(strstr(hstr_config,HH_CONFIG_BIG_KEYS_FLOOR)) {
307 hstr->bigKeys=RADIX_BIG_KEYS_FLOOR;
308 } else {
309 hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
310 }
311 }
298 312
299 313 if(strstr(hstr_config,HH_CONFIG_DEBUG)) { if(strstr(hstr_config,HH_CONFIG_DEBUG)) {
300 314 hstr->debugLevel=HH_DEBUG_LEVEL_DEBUG; hstr->debugLevel=HH_DEBUG_LEVEL_DEBUG;
 
... ... void hstr_init_favorites(Hstr *hstr)
1103 1117
1104 1118 void hstr_main(Hstr *hstr) void hstr_main(Hstr *hstr)
1105 1119 { {
1106 hstr->history=get_prioritized_history();
1120 hstr->history=get_prioritized_history(hstr->bigKeys);
1107 1121 if(hstr->history) { if(hstr->history) {
1108 1122 history_mgmt_open(); history_mgmt_open();
1109 1123 if(hstr->interactive) { if(hstr->interactive) {
File src/hstr_history.c changed (mode: 100644) (index acae663..c24be88)
... ... int get_item_offset()
86 86 } }
87 87 } }
88 88
89 HistoryItems *get_prioritized_history()
89 HistoryItems *get_prioritized_history(int optionBigKeys)
90 90 { {
91 91 using_history(); using_history();
92 92
 
... ... HistoryItems *get_prioritized_history()
114 114 RadixSorter rs; RadixSorter rs;
115 115 unsigned radixMaxKeyEstimate=historyState->size*1000; unsigned radixMaxKeyEstimate=historyState->size*1000;
116 116 radixsort_init(&rs, (radixMaxKeyEstimate<100000?100000:radixMaxKeyEstimate)); radixsort_init(&rs, (radixMaxKeyEstimate<100000?100000:radixMaxKeyEstimate));
117 rs.optFloorAndInsertBigKeys=true;
117 rs.optionBigKeys=optionBigKeys;
118 118
119 119 regex_t regexp; regex_t regexp;
120 120 // HISTTIMEFORMAT defined > ^#1234567890$ // HISTTIMEFORMAT defined > ^#1234567890$
File src/include/hstr_history.h changed (mode: 100644) (index a2e2528..8b99074)
... ... typedef struct {
40 40 unsigned rawCount; unsigned rawCount;
41 41 } HistoryItems; } HistoryItems;
42 42
43 HistoryItems *get_prioritized_history();
43 HistoryItems *get_prioritized_history(int optionBigKeys);
44 44
45 45 HistoryItems *get_history_items(); HistoryItems *get_history_items();
46 46 void free_history_items(); void free_history_items();
File src/include/radixsort.h changed (mode: 100644) (index cbb5cfc..0742983)
10 10 #ifndef RADIXSORT_H_ #ifndef RADIXSORT_H_
11 11 #define RADIXSORT_H_ #define RADIXSORT_H_
12 12
13 #include <stdbool.h>
13 14 #include <stdlib.h> #include <stdlib.h>
14 15 #include <stdio.h> #include <stdio.h>
15 16 #include <math.h> #include <math.h>
 
19 20
20 21 #define RADIX_SLOT_SIZE 1000 #define RADIX_SLOT_SIZE 1000
21 22
23 #define RADIX_BIG_KEYS_SKIP 0
24 #define RADIX_BIG_KEYS_FLOOR 1
25 #define RADIX_BIG_KEYS_EXIT 2
26
22 27 #define RADIX_DEBUG_LEVEL_NONE 0 #define RADIX_DEBUG_LEVEL_NONE 0
23 28 #define RADIX_DEBUG_LEVEL_WARN 1 #define RADIX_DEBUG_LEVEL_WARN 1
24 29 #define RADIX_DEBUG_LEVEL_DEBUG 2 #define RADIX_DEBUG_LEVEL_DEBUG 2
 
... ... typedef struct {
41 46 unsigned keyLimit; unsigned keyLimit;
42 47 RadixItem ***topDigits; RadixItem ***topDigits;
43 48
44 bool optFloorAndInsertBigKeys;
45 bool optIgnoreBigKeys;
49 int optionBigKeys;
46 50
47 51 RadixSlot **_slotDescriptors; RadixSlot **_slotDescriptors;
48 52 unsigned _slotsCount; unsigned _slotsCount;
File src/radixsort.c changed (mode: 100644) (index 6ab0d4e..fd91338)
14 14
15 15 void radixsort_init(RadixSorter *rs, unsigned keyLimit) void radixsort_init(RadixSorter *rs, unsigned keyLimit)
16 16 { {
17 rs->optFloorAndInsertBigKeys=false;
18 rs->optIgnoreBigKeys=false;
17 rs->optionBigKeys=RADIX_BIG_KEYS_SKIP;
19 18
20 19 rs->_topIndexLimit=GET_TOP_INDEX(keyLimit); rs->_topIndexLimit=GET_TOP_INDEX(keyLimit);
21 20 rs->size=0; rs->size=0;
 
... ... void radixsort_add(RadixSorter *rs, RadixItem *item)
54 53 if(rs->_debug > RADIX_DEBUG_LEVEL_NONE) { if(rs->_debug > RADIX_DEBUG_LEVEL_NONE) {
55 54 fprintf(stderr, "WARNING: Radix sort overflow - inserted key is bigger than limit (%u): %u\n", rs->keyLimit, item->key); fprintf(stderr, "WARNING: Radix sort overflow - inserted key is bigger than limit (%u): %u\n", rs->keyLimit, item->key);
56 55 } }
57 if(rs->optFloorAndInsertBigKeys) {
56 if(rs->optionBigKeys==RADIX_BIG_KEYS_FLOOR) {
58 57 item->key = rs->keyLimit-1; item->key = rs->keyLimit-1;
59 58 } else { } else {
60 if(rs->optIgnoreBigKeys) {
59 if(rs->optionBigKeys==RADIX_BIG_KEYS_SKIP) {
61 60 return; return;
62 61 } else { } else {
63 62 exit(0); exit(0);
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