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 ed9ab79887d5e29efbf29f31ac4c707d9590a644

Improved ranking function.
Author: Martin Dvorak
Author date (UTC): 2013-12-15 11:21
Committer name: Martin Dvorak
Committer date (UTC): 2013-12-15 11:21
Parent(s): 35513e47d0dd567a824e01d981e2b8b8d7cd5815
Signing key:
Tree: f1410539f5e4ff8f3f17787bb3049766dd6d74f6
File Lines added Lines deleted
src/hstr_history.c 15 10
File src/hstr_history.c changed (mode: 100644) (index a4731c5..cde4a97)
12 12 #include "include/hashmap.h" #include "include/hashmap.h"
13 13 #include "include/radixsort.h" #include "include/radixsort.h"
14 14
15 #define NDEBUG
16 #include <assert.h>
17
15 18 typedef struct { typedef struct {
16 19 char *item; char *item;
17 20 unsigned rank; unsigned rank;
 
... ... typedef struct {
20 23 static HistoryItems *history; static HistoryItems *history;
21 24 static HistoryItems *prioritizedHistory; static HistoryItems *prioritizedHistory;
22 25
26 unsigned history_ranking_function(unsigned rank, unsigned newOccurenceOrder, unsigned lng) {
27 rank+=newOccurenceOrder/10 + lng;
28 return rank;
29 }
30
23 31 char *get_history_file() { char *get_history_file() {
24 32 char *home = getenv(ENV_VAR_HOME); char *home = getenv(ENV_VAR_HOME);
25 33 char *fileName = (char*) malloc( char *fileName = (char*) malloc(
26 34 strlen(home) + 1 + strlen(FILE_HISTORY) + 1); strlen(home) + 1 + strlen(FILE_HISTORY) + 1);
27 strcpy(fileName, home);
28 strcat(fileName, "/");
29 strcat(fileName, FILE_HISTORY);
35 strcat(strcat(strcpy(fileName, home), "/"), FILE_HISTORY);
30 36 return fileName; return fileName;
31 37 } }
32 38
33 #define history_ranking_function(RANK, NEWORDEROCCURENCE) (RANK?RANK+NEWORDEROCCURENCE:NEWORDEROCCURENCE)
34
35 39 void dump_prioritized_history(HistoryItems *ph) { void dump_prioritized_history(HistoryItems *ph) {
36 40 printf("\n\nPrioritized history:"); printf("\n\nPrioritized history:");
37 41 int i; int i;
 
... ... HistoryItems *prioritize_history(HistoryItems *historyFileItems) {
68 72 } }
69 73 if((r=hashmap_get(&rankmap, historyFileItems->items[i]))==NULL) { if((r=hashmap_get(&rankmap, historyFileItems->items[i]))==NULL) {
70 74 r=(RankedHistoryItem *)malloc(sizeof(RankedHistoryItem)); r=(RankedHistoryItem *)malloc(sizeof(RankedHistoryItem));
71 r->rank=history_ranking_function(0, i);
75 r->rank=history_ranking_function(0, i, strlen(historyFileItems->items[i]));
72 76 r->item=historyFileItems->items[i]; r->item=historyFileItems->items[i];
73 77
74 78 hashmap_put(&rankmap, historyFileItems->items[i], r); hashmap_put(&rankmap, historyFileItems->items[i], r);
 
... ... HistoryItems *prioritize_history(HistoryItems *historyFileItems) {
79 83 radixItem->next=NULL; radixItem->next=NULL;
80 84 radixsort_add(&rs, radixItem); radixsort_add(&rs, radixItem);
81 85 } else { } else {
82 //printf("\n>>> %s ", r->item); fflush(stdout);
83 86 radixItem=radix_cut(&rs, r->rank, r); radixItem=radix_cut(&rs, r->rank, r);
84 87
85 if(radixItem!=NULL) {
86 r->rank=history_ranking_function(r->rank, i);
88 assert(radixItem);
89
90 if(radixItem) {
91 r->rank=history_ranking_function(r->rank, i, strlen(historyFileItems->items[i]));
87 92 radixItem->key=r->rank; radixItem->key=r->rank;
88 93 radixsort_add(&rs, radixItem); radixsort_add(&rs, radixItem);
89 } // TODO else assert
94 }
90 95 } }
91 96 } }
92 97
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