mirror of
https://github.com/dvorka/hstr.git
synced 2024-12-28 18:50:54 +08:00
Fixing #107 by making big keys handling in radix sort an option.
This commit is contained in:
parent
207bb1f634
commit
e3938d53c7
6 changed files with 45 additions and 16 deletions
22
man/hh.1
22
man/hh.1
|
@ -41,7 +41,7 @@ Toggle regular expression and substring search.
|
|||
Toggle case sensitive search.
|
||||
.TP
|
||||
\fBCtrl\-/\fR, \fBCtrl\-7\fR
|
||||
Rotate view of history as provided by BASH, ranked history ordered by the number of occurences/length/timestamp and favorites.
|
||||
Rotate view of history as provided by Bash, ranked history ordered by the number of occurences/length/timestamp and favorites.
|
||||
.TP
|
||||
\fBCtrl\-f\fR
|
||||
Add currently selected command to favorites.
|
||||
|
@ -56,7 +56,7 @@ Navigate in the history list.
|
|||
Choose currently selected item for completion and let user to edit it on the command prompt.
|
||||
.TP
|
||||
\fBLEFT\fR arrow
|
||||
Choose currently selected item for completion and let user to edit it editor (fix command).
|
||||
Choose currently selected item for completion and let user to edit it in editor (fix command).
|
||||
.TP
|
||||
\fBENTER\fR
|
||||
Choose currently selected item for completion and execute it.
|
||||
|
@ -85,7 +85,7 @@ Configuration options:
|
|||
Get more colors with this option (default is monochromatic).
|
||||
|
||||
\fImonochromatic\fR
|
||||
Ensure black and white view with this option.
|
||||
Ensure black and white view.
|
||||
|
||||
\fIregexp\fR
|
||||
Filter command history using regular expressions (substring match is default)
|
||||
|
@ -105,6 +105,15 @@ Configuration options:
|
|||
\fIfavorites\fR
|
||||
Show favorites as a default view (metric-based view is shown otherwise).
|
||||
|
||||
\fIbigkeysskip\fR
|
||||
Skip big history entries i.e. very long lines (default).
|
||||
|
||||
\fIbigkeysfloor\fR
|
||||
Use different sorting slot for big keys when building metrics-based view (big keys are skipped by default).
|
||||
|
||||
\fIbigkeysexit\fR
|
||||
Exit (fail) on presence of a big key in history (big keys are skipped by default).
|
||||
|
||||
\fIwarning\fR
|
||||
Show warning.
|
||||
|
||||
|
@ -151,11 +160,14 @@ bindkey -s "\eC\-r" "\eeqhh\en" # bind hh to Ctrl-r (for Vi mode check doc)
|
|||
.fi
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
\fBhh git\fR
|
||||
Start `hh` and show only history items containing 'git'.
|
||||
.TP
|
||||
\fBhh --non-interactive git\fR
|
||||
Print history items containing 'git' to standard output and exit.
|
||||
Print history items containing 'git' to standard output and exit.
|
||||
.TP
|
||||
\fBhh --show-configuration >> ~/.bashrc\fR
|
||||
Append default \fBhh\fR configuration to your Bash profile.
|
||||
Append default \fBhh\fR configuration to your Bash profile.
|
||||
.SH AUTHOR
|
||||
Written by Martin Dvorak <martin.dvorak@mindforger.com>
|
||||
.SH BUGS
|
||||
|
|
18
src/hstr.c
18
src/hstr.c
|
@ -93,6 +93,9 @@
|
|||
#define HH_CONFIG_FAVORITES "favorites"
|
||||
#define HH_CONFIG_DEBUG "debug"
|
||||
#define HH_CONFIG_WARN "warning"
|
||||
#define HH_CONFIG_BIG_KEYS_SKIP "bigkeysskip"
|
||||
#define HH_CONFIG_BIG_KEYS_FLOOR "bigkeysfloor"
|
||||
#define HH_CONFIG_BIG_KEYS_EXIT "bigkeysexit"
|
||||
|
||||
#define HH_DEBUG_LEVEL_NONE 0
|
||||
#define HH_DEBUG_LEVEL_WARN 1
|
||||
|
@ -239,6 +242,7 @@ typedef struct {
|
|||
bool interactive;
|
||||
|
||||
bool hicolor;
|
||||
int bigKeys;
|
||||
int debugLevel;
|
||||
|
||||
HstrRegexp regexp;
|
||||
|
@ -261,8 +265,9 @@ void hstr_init(Hstr *hstr)
|
|||
hstr->interactive=true;
|
||||
|
||||
hstr->hicolor=FALSE;
|
||||
|
||||
hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
|
||||
hstr->debugLevel=HH_DEBUG_LEVEL_NONE;
|
||||
|
||||
hstr->cmdline[0]=0;
|
||||
hstr_regexp_init(&hstr->regexp);
|
||||
}
|
||||
|
@ -295,6 +300,15 @@ void hstr_get_env_configuration(Hstr *hstr)
|
|||
hstr->historyView=HH_VIEW_FAVORITES;
|
||||
}
|
||||
}
|
||||
if(strstr(hstr_config,HH_CONFIG_BIG_KEYS_EXIT)) {
|
||||
hstr->bigKeys=RADIX_BIG_KEYS_EXIT;
|
||||
} else {
|
||||
if(strstr(hstr_config,HH_CONFIG_BIG_KEYS_FLOOR)) {
|
||||
hstr->bigKeys=RADIX_BIG_KEYS_FLOOR;
|
||||
} else {
|
||||
hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
|
||||
}
|
||||
}
|
||||
|
||||
if(strstr(hstr_config,HH_CONFIG_DEBUG)) {
|
||||
hstr->debugLevel=HH_DEBUG_LEVEL_DEBUG;
|
||||
|
@ -1103,7 +1117,7 @@ void hstr_init_favorites(Hstr *hstr)
|
|||
|
||||
void hstr_main(Hstr *hstr)
|
||||
{
|
||||
hstr->history=get_prioritized_history();
|
||||
hstr->history=get_prioritized_history(hstr->bigKeys);
|
||||
if(hstr->history) {
|
||||
history_mgmt_open();
|
||||
if(hstr->interactive) {
|
||||
|
|
|
@ -86,7 +86,7 @@ int get_item_offset()
|
|||
}
|
||||
}
|
||||
|
||||
HistoryItems *get_prioritized_history()
|
||||
HistoryItems *get_prioritized_history(int optionBigKeys)
|
||||
{
|
||||
using_history();
|
||||
|
||||
|
@ -114,7 +114,7 @@ HistoryItems *get_prioritized_history()
|
|||
RadixSorter rs;
|
||||
unsigned radixMaxKeyEstimate=historyState->size*1000;
|
||||
radixsort_init(&rs, (radixMaxKeyEstimate<100000?100000:radixMaxKeyEstimate));
|
||||
rs.optFloorAndInsertBigKeys=true;
|
||||
rs.optionBigKeys=optionBigKeys;
|
||||
|
||||
regex_t regexp;
|
||||
// HISTTIMEFORMAT defined > ^#1234567890$
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef struct {
|
|||
unsigned rawCount;
|
||||
} HistoryItems;
|
||||
|
||||
HistoryItems *get_prioritized_history();
|
||||
HistoryItems *get_prioritized_history(int optionBigKeys);
|
||||
|
||||
HistoryItems *get_history_items();
|
||||
void free_history_items();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef RADIXSORT_H_
|
||||
#define RADIXSORT_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
@ -19,6 +20,10 @@
|
|||
|
||||
#define RADIX_SLOT_SIZE 1000
|
||||
|
||||
#define RADIX_BIG_KEYS_SKIP 0
|
||||
#define RADIX_BIG_KEYS_FLOOR 1
|
||||
#define RADIX_BIG_KEYS_EXIT 2
|
||||
|
||||
#define RADIX_DEBUG_LEVEL_NONE 0
|
||||
#define RADIX_DEBUG_LEVEL_WARN 1
|
||||
#define RADIX_DEBUG_LEVEL_DEBUG 2
|
||||
|
@ -41,8 +46,7 @@ typedef struct {
|
|||
unsigned keyLimit;
|
||||
RadixItem ***topDigits;
|
||||
|
||||
bool optFloorAndInsertBigKeys;
|
||||
bool optIgnoreBigKeys;
|
||||
int optionBigKeys;
|
||||
|
||||
RadixSlot **_slotDescriptors;
|
||||
unsigned _slotsCount;
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
void radixsort_init(RadixSorter *rs, unsigned keyLimit)
|
||||
{
|
||||
rs->optFloorAndInsertBigKeys=false;
|
||||
rs->optIgnoreBigKeys=false;
|
||||
rs->optionBigKeys=RADIX_BIG_KEYS_SKIP;
|
||||
|
||||
rs->_topIndexLimit=GET_TOP_INDEX(keyLimit);
|
||||
rs->size=0;
|
||||
|
@ -54,10 +53,10 @@ void radixsort_add(RadixSorter *rs, RadixItem *item)
|
|||
if(rs->_debug > RADIX_DEBUG_LEVEL_NONE) {
|
||||
fprintf(stderr, "WARNING: Radix sort overflow - inserted key is bigger than limit (%u): %u\n", rs->keyLimit, item->key);
|
||||
}
|
||||
if(rs->optFloorAndInsertBigKeys) {
|
||||
if(rs->optionBigKeys==RADIX_BIG_KEYS_FLOOR) {
|
||||
item->key = rs->keyLimit-1;
|
||||
} else {
|
||||
if(rs->optIgnoreBigKeys) {
|
||||
if(rs->optionBigKeys==RADIX_BIG_KEYS_SKIP) {
|
||||
return;
|
||||
} else {
|
||||
exit(0);
|
||||
|
|
Loading…
Reference in a new issue