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 5bda0921347ff156f186c8c284c25bd8e314a030

An attempt to fix #51: extended radix sort limit and made radix sort more robuts (huge key protection).
Author: Martin Dvorak
Author date (UTC): 2014-01-30 21:39
Committer name: Martin Dvorak
Committer date (UTC): 2014-01-30 21:39
Parent(s): d072e30063ac031393ebc214ac4aebf26e32afc9
Signing key:
Tree: 577b9a1b0a723335f2de1bc955982bada9649817
File Lines added Lines deleted
dist/ubuntu-env.sh 4 4
src/hstr.c 1 1
src/hstr_history.c 4 2
src/include/radixsort.h 1 0
src/radixsort.c 19 5
tests/_ranking 0 0
tests/src/test_ranking.c 20 2
File dist/ubuntu-env.sh changed (mode: 100755) (index 9ad9170..d3e69c3)
1 1 #!/bin/bash #!/bin/bash
2 2
3 export HHVERSION="1.7.4"
3 export HHVERSION="1.7.8"
4 4 export HHFULLVERSION=${HHVERSION}-0ubuntu1 export HHFULLVERSION=${HHVERSION}-0ubuntu1
5 5 export HH=hh_${HHVERSION} export HH=hh_${HHVERSION}
6 6 export HHRELEASE=hh_${HHFULLVERSION} export HHRELEASE=hh_${HHFULLVERSION}
 
... ... export NOW=`date +%Y-%m-%d--%H-%M-%S`
9 9 export HHBUILD=hstr-${NOW} export HHBUILD=hstr-${NOW}
10 10
11 11 #export UBUNTUVERSION=quantal #export UBUNTUVERSION=quantal
12 #export UBUNTUVERSION=raring
13 export UBUNTUVERSION=saucy
12 export UBUNTUVERSION=raring
13 #export UBUNTUVERSION=saucy
14 14
15 export HHBZRMSG="Color version and env var configuration."
15 export HHBZRMSG="Fixing broken propagation of commands from cmd line."
16 16
17 17 # - user email must be the same as in gpg i.e. (Dvorka) must present # - user email must be the same as in gpg i.e. (Dvorka) must present
18 18 # - hh_ must be with underscore (dh_make enforced) # - hh_ must be with underscore (dh_make enforced)
File src/hstr.c changed (mode: 100644) (index 5b7396b..51a8314)
58 58 #define HH_COLOR_PROMPT 3 #define HH_COLOR_PROMPT 3
59 59 #define HH_COLOR_DELETE 4 #define HH_COLOR_DELETE 4
60 60
61 #define ENV_VAR_HH_CONFIG "HH_CONFIG"
61 #define ENV_VAR_HH_CONFIG "HH_CONFIG"
62 62 #define HH_CONFIG_HICOLOR "hicolor" #define HH_CONFIG_HICOLOR "hicolor"
63 63 #define HH_CONFIG_CASE "casesensitive" #define HH_CONFIG_CASE "casesensitive"
64 64 #define HH_CONFIG_SORTING "rawhistory" #define HH_CONFIG_SORTING "rawhistory"
File src/hstr_history.c changed (mode: 100644) (index 3014850..922b4b0)
... ... static const char *commandBlacklist[] = {
35 35 #endif #endif
36 36
37 37 unsigned history_ranking_function(unsigned rank, int newOccurenceOrder, size_t length) { unsigned history_ranking_function(unsigned rank, int newOccurenceOrder, size_t length) {
38 //long metrics=rank+newOccurenceOrder/10+length;
38 // long metrics = rank+newOccurenceOrder/10+length;
39 39 long metrics=rank+(log(newOccurenceOrder)*10.0)+length; long metrics=rank+(log(newOccurenceOrder)*10.0)+length;
40 40 assert(metrics<UINT_MAX); assert(metrics<UINT_MAX);
41 41 return metrics; return metrics;
 
... ... HistoryItems *get_prioritized_history()
90 90 } }
91 91
92 92 RadixSorter rs; RadixSorter rs;
93 radixsort_init(&rs, 100000);
93 // TODO quick fix to enable loading of huge history files (2x800kB allocated) > malloc this
94 // based on the expected max value (inferred from history file size, # of rows, row size)
95 radixsort_init(&rs, 100000000);
94 96
95 97 RankedHistoryItem *r; RankedHistoryItem *r;
96 98 RadixItem *radixItem; RadixItem *radixItem;
File src/include/radixsort.h changed (mode: 100644) (index 8be8172..1b4b6bc)
... ... typedef struct {
39 39
40 40 RadixSlot **_slotDescriptors; RadixSlot **_slotDescriptors;
41 41 unsigned _slotsCount; unsigned _slotsCount;
42 unsigned _topIndexLimit;
42 43 } RadixSorter; } RadixSorter;
43 44
44 45 void radixsort_init(RadixSorter *rs, unsigned keyLimit); void radixsort_init(RadixSorter *rs, unsigned keyLimit);
File src/radixsort.c changed (mode: 100644) (index 4dfb0b3..895cee4)
1 /*
1 /*"
2 2 ============================================================================ ============================================================================
3 3 Name : radixsort.c Name : radixsort.c
4 4 Author : martin.dvorak@midforger.com Author : martin.dvorak@midforger.com
 
12 12 #define GET_TOP_INDEX(KEY) KEY/SLOT_SIZE #define GET_TOP_INDEX(KEY) KEY/SLOT_SIZE
13 13 #define GET_LOW_INDEX(KEY) KEY%SLOT_SIZE #define GET_LOW_INDEX(KEY) KEY%SLOT_SIZE
14 14
15 #define RADIX_DEBUG 0
16 #define RADIX_STRICT 0
17
15 18 void radixsort_init(RadixSorter *rs, unsigned keyLimit) void radixsort_init(RadixSorter *rs, unsigned keyLimit)
16 19 { {
17 unsigned topIndexLimit=GET_TOP_INDEX(keyLimit);
20 rs->_topIndexLimit=GET_TOP_INDEX(keyLimit);
18 21 rs->size=0; rs->size=0;
19 rs->topDigits=malloc(topIndexLimit * sizeof(RadixItem ***));
20 memset(rs->topDigits, 0, topIndexLimit * sizeof(RadixItem ***));
22 rs->topDigits=malloc(rs->_topIndexLimit * sizeof(RadixItem ***));
23 memset(rs->topDigits, 0, rs->_topIndexLimit * sizeof(RadixItem ***));
21 24 rs->maxKey=0; rs->maxKey=0;
22 25 rs->keyLimit=keyLimit; rs->keyLimit=keyLimit;
23 26
24 rs->_slotDescriptors=malloc(topIndexLimit * sizeof(RadixSlot **));
27 rs->_slotDescriptors=malloc(rs->_topIndexLimit * sizeof(RadixSlot **));
25 28 rs->_slotsCount=0; rs->_slotsCount=0;
26 29 } }
27 30
 
... ... RadixItem **radixsort_get_slot(RadixSorter *rs, unsigned topIndex)
42 45
43 46 void radixsort_add(RadixSorter *rs, RadixItem *item) void radixsort_add(RadixSorter *rs, RadixItem *item)
44 47 { {
48 if(item->key > rs->keyLimit) {
49 if(RADIX_DEBUG) {
50 fprintf(stderr, "ERROR: Radix sort overflow - value to be inserted in radix is too big: %i (limit: %i)\n", item->key, rs->keyLimit);
51 }
52 if(RADIX_STRICT) {
53 exit(0);
54 } else {
55 return;
56 }
57 }
58
45 59 unsigned topIndex = GET_TOP_INDEX(item->key); unsigned topIndex = GET_TOP_INDEX(item->key);
46 60 unsigned lowIndex = GET_LOW_INDEX(item->key); unsigned lowIndex = GET_LOW_INDEX(item->key);
47 61
File tests/_ranking changed (mode: 100755) (index 6e660b6..27ba1e3)
File tests/src/test_ranking.c changed (mode: 100644) (index d93c528..d055bf4)
... ... void testLog() {
8 8 const int HISTORY_SIZE=2000; const int HISTORY_SIZE=2000;
9 9 int i; int i;
10 10 for(i=0; i<HISTORY_SIZE; i++) { for(i=0; i<HISTORY_SIZE; i++) {
11 printf("\n%d # l: %f # l10: %f # l2: %f",i,log(i), log10(i), log2(i));
11 printf("\n%d # l: %f # l10: %f # l2: %f", i, log(i), log10(i), log2(i));
12 12 } }
13 13 } }
14 14
15 #define MAX_CHARACTER_CODE 10000
16 static char line[MAX_CHARACTER_CODE];
17
18 void testGenerateCrazyHistoryFile()
19 {
20 FILE *file = fopen(".bash_history_crazy","a");
21 fseek(file,0, SEEK_END);
22
23 line[0]=0;
24 int i;
25 for(i=0; i<MAX_CHARACTER_CODE; i++) {
26 sprintf(line,"%s%c",line,i);
27 fprintf(file,"%s\n",line);
28 }
29
30 fclose(file);
31 }
32
15 33 int main(int argc, char *argv[]) int main(int argc, char *argv[])
16 34 { {
17 testLog();
35 testGenerateCrazyHistoryFile();
18 36 } }
19 37
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