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 595e18970a9546dbe881b432e43df5c8c6af2a16

Fixing #131 by filtering history timestamps out of the raw history & condensing raw history & setting the right length.
Author: Martin Dvorak
Author date (UTC): 2015-02-24 06:23
Committer name: Martin Dvorak
Committer date (UTC): 2015-02-24 06:23
Parent(s): 1271343427f24d407f7816055fd575df1378fd78
Signing key:
Tree: 74123d5a4e581a98871358cb1e6fad2d7f8e7c73
File Lines added Lines deleted
src/hstr_history.c 17 5
tests/resources/.bash_history_131_A 0 0
tests/resources/.bash_history_131_B 6 0
File src/hstr_history.c changed (mode: 100644) (index 2b1dd4e..acae663)
... ... static const char *commandBlacklist[] = {
36 36 #define DEBUG_RADIXSORT() #define DEBUG_RADIXSORT()
37 37 #endif #endif
38 38
39 // TODO make this configurable from command line as option
40 #define METRICS_LOGARITHM(RANK,ORDER,LENGTH) RANK+(log(ORDER)*10.0)+LENGTH
41 #define METRICS_ADDITIVE(RANK,ORDER,LENGTH) RANK+ORDER/10+LENGTH
42
39 43 unsigned history_ranking_function(unsigned rank, int newOccurenceOrder, size_t length) { unsigned history_ranking_function(unsigned rank, int newOccurenceOrder, size_t length) {
40 long metrics=rank+(log(newOccurenceOrder)*10.0)+length;
41 // alternative metrics:
42 // rank+newOccurenceOrder/10+length
44 long metrics=METRICS_LOGARITHM(rank, newOccurenceOrder, length);
43 45 assert(metrics<UINT_MAX); assert(metrics<UINT_MAX);
44 46 return metrics; return metrics;
45 47 } }
 
... ... HistoryItems *get_prioritized_history()
123 125 RadixItem *radixItem; RadixItem *radixItem;
124 126 HIST_ENTRY **historyList=history_list(); HIST_ENTRY **historyList=history_list();
125 127 char **rawHistory=malloc(sizeof(char*) * historyState->length); char **rawHistory=malloc(sizeof(char*) * historyState->length);
126 int rawOffset=historyState->length-1;
128 int rawOffset=historyState->length-1, rawTimestamps=0;
127 129 char *line; char *line;
128 130 for(i=0; i<historyState->length; i++, rawOffset--) { for(i=0; i<historyState->length; i++, rawOffset--) {
129 131 if(!regexp_match(&regexp, historyList[i]->line)) { if(!regexp_match(&regexp, historyList[i]->line)) {
132 rawHistory[rawOffset]=0;
133 rawTimestamps++;
130 134 continue; continue;
131 135 } }
132 136 if(historyList[i]->line && strlen(historyList[i]->line)>itemOffset) { if(historyList[i]->line && strlen(historyList[i]->line)>itemOffset) {
 
... ... HistoryItems *get_prioritized_history()
162 166 } }
163 167 } }
164 168 } }
169 if(rawTimestamps) {
170 rawOffset=0;
171 for(i=0; i<historyState->length; i++) {
172 if(rawHistory[i]) {
173 rawHistory[rawOffset++]=rawHistory[i];
174 }
175 }
176 }
165 177
166 178 regfree(&regexp); regfree(&regexp);
167 179
 
... ... HistoryItems *get_prioritized_history()
170 182 RadixItem **prioritizedRadix=radixsort_dump(&rs); RadixItem **prioritizedRadix=radixsort_dump(&rs);
171 183 prioritizedHistory=malloc(sizeof(HistoryItems)); prioritizedHistory=malloc(sizeof(HistoryItems));
172 184 prioritizedHistory->count=rs.size; prioritizedHistory->count=rs.size;
173 prioritizedHistory->rawCount=historyState->length;
185 prioritizedHistory->rawCount=historyState->length-rawTimestamps;
174 186 prioritizedHistory->items=malloc(rs.size * sizeof(char*)); prioritizedHistory->items=malloc(rs.size * sizeof(char*));
175 187 prioritizedHistory->rawItems=rawHistory; prioritizedHistory->rawItems=rawHistory;
176 188 for(i=0; i<rs.size; i++) { for(i=0; i<rs.size; i++) {
File tests/resources/.bash_history_131_A copied from file tests/resources/.bash_history_ROTATE_VIEW_CRASH_131 (similarity 100%)
File tests/resources/.bash_history_131_B added (mode: 100644) (index 0000000..b2f210d)
1 #1234567890
2 foo
3 #1234567892
4 bar
5 #1234567891
6 blah
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