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 cde0b2cd98f4d668ef19c9f3ae6f1edbae18e3a3

Fixed #91 by sending pattern on cmdline when there is no match and user hits Enter/TAB/RIGHT ARROW.

Author: Martin Dvorak
Author date (UTC): 2014-05-07 16:24
Committer: Martin Dvorak
Commit date (UTC): 2014-05-07 16:24
Tree: 281b0ee6c8c6965df27f9c361eb03b586fb053a4
Parents: c71530db1c7e97912879a9e2471e37287f8fbef5
File Lines added Lines deleted
src/hashset.c 4 1
src/hstr.c 9 9
src/hstr_favorites.c 2 0
src/include/hashset.h 1 1
src/include/hstr_favorites.h 2 0

File src/hashset.c changed (mode: 100644) (index ecfadde..aec790a)
... ... char** hashset_keys(const HashSet *hs)
100 100 return NULL; return NULL;
101 101 } }
102 102
103 void hashset_destroy(const HashSet *hs)
103 void hashset_destroy(HashSet *hs)
104 104 { {
105 105 // TODO to be implemented // TODO to be implemented
106 if(hs) {
107 free(hs);
108 }
106 109 } }

File src/hstr.c changed (mode: 100644) (index d08a4dc..51f2505)
... ... void print_history_label(Hstr *hstr)
336 336 int width=getmaxx(stdscr); int width=getmaxx(stdscr);
337 337
338 338 char screenLine[CMDLINE_LNG]; char screenLine[CMDLINE_LNG];
339 snprintf(screenLine, width, "- HISTORY - view:%s (C-/) - match:%s (C-e) - case:%s (C-t) - %d/%d ",
339 snprintf(screenLine, width, "- HISTORY - view:%s (C-/) - match:%s (C-e) - case:%s (C-t) - %d/%d/%d ",
340 340 HH_VIEW_LABELS[hstr->historyView], HH_VIEW_LABELS[hstr->historyView],
341 341 HH_MATCH_LABELS[hstr->historyMatch], HH_MATCH_LABELS[hstr->historyMatch],
342 342 HH_CASE_LABELS[hstr->caseSensitive], HH_CASE_LABELS[hstr->caseSensitive],
343 343 hstr->history->count, hstr->history->count,
344 hstr->history->rawCount);
344 hstr->history->rawCount,
345 hstr->favorites->count);
345 346 width -= strlen(screenLine); width -= strlen(screenLine);
346 347 unsigned i; unsigned i;
347 348 for (i=0; i < width; i++) { for (i=0; i < width; i++) {
 
... ... void loop_to_select(Hstr *hstr)
758 759 // TODO make this a function // TODO make this a function
759 760 result=hstr_print_selection(maxHistoryItems, pattern, hstr); result=hstr_print_selection(maxHistoryItems, pattern, hstr);
760 761 print_history_label(hstr); print_history_label(hstr);
761 selectionCursorPosition=0;
762 selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
762 763 if(strlen(pattern)<(width-basex-1)) { if(strlen(pattern)<(width-basex-1)) {
763 764 print_prefix(pattern, y, basex); print_prefix(pattern, y, basex);
764 765 cursorX=getcurx(stdscr); cursorX=getcurx(stdscr);
 
... ... void loop_to_select(Hstr *hstr)
770 771 hstr->regexp.caseSensitive=hstr->caseSensitive; hstr->regexp.caseSensitive=hstr->caseSensitive;
771 772 result=hstr_print_selection(maxHistoryItems, pattern, hstr); result=hstr_print_selection(maxHistoryItems, pattern, hstr);
772 773 print_history_label(hstr); print_history_label(hstr);
773 selectionCursorPosition=0;
774 selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
774 775 if(strlen(pattern)<(width-basex-1)) { if(strlen(pattern)<(width-basex-1)) {
775 776 print_prefix(pattern, y, basex); print_prefix(pattern, y, basex);
776 777 cursorX=getcurx(stdscr); cursorX=getcurx(stdscr);
 
... ... void loop_to_select(Hstr *hstr)
800 801 printDefaultLabel=TRUE; printDefaultLabel=TRUE;
801 802 } }
802 803 result=hstr_print_selection(maxHistoryItems, pattern, hstr); result=hstr_print_selection(maxHistoryItems, pattern, hstr);
803 selectionCursorPosition=0;
804 selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
804 805 } }
805 806 break; break;
806 807 case KEY_RESIZE: case KEY_RESIZE:
807 808 print_history_label(hstr); print_history_label(hstr);
808 809 result=hstr_print_selection(maxHistoryItems, pattern, hstr); result=hstr_print_selection(maxHistoryItems, pattern, hstr);
809 810 print_history_label(hstr); print_history_label(hstr);
810 selectionCursorPosition=0;
811 selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
811 812 move(y, basex+strlen(pattern)); move(y, basex+strlen(pattern));
812 813 break; break;
813 814 case K_CTRL_U: case K_CTRL_U:
 
... ... void loop_to_select(Hstr *hstr)
819 820 toggle_case(pattern, lowercase); toggle_case(pattern, lowercase);
820 821 lowercase=!lowercase; lowercase=!lowercase;
821 822 print_prefix(pattern, y, basex); print_prefix(pattern, y, basex);
822 selectionCursorPosition=0;
823 selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
823 824 break; break;
824 825 case K_CTRL_H: case K_CTRL_H:
825 826 case K_BACKSPACE: case K_BACKSPACE:
 
... ... void loop_to_select(Hstr *hstr)
879 880 favorites_choose(hstr->favorites,result); favorites_choose(hstr->favorites,result);
880 881 } }
881 882 } else { } else {
882 executeResult=FALSE;
883 break;
883 result=(pattern==NULL?"":pattern);
884 884 } }
885 885 done=TRUE; done=TRUE;
886 886 break; break;

File src/hstr_favorites.c changed (mode: 100644) (index b53451f..8d06d21)
... ... void favorites_init(FavoriteItems *favorites)
21 21 favorites->items=NULL; favorites->items=NULL;
22 22 favorites->count=0; favorites->count=0;
23 23 favorites->loaded=false; favorites->loaded=false;
24 favorites->set=malloc(sizeof(HashSet));
24 25 } }
25 26
26 27 void favorites_show(FavoriteItems *favorites) void favorites_show(FavoriteItems *favorites)
 
... ... void favorites_destroy(FavoriteItems *favorites)
187 188 free(favorites->items[i]); free(favorites->items[i]);
188 189 } }
189 190 free(favorites); free(favorites);
191 hashset_destroy(favorites->set);
190 192 } }
191 193 } }

File src/include/hashset.h changed (mode: 100644) (index b6424e3..e7e5715)
... ... int hashset_put(HashSet *hm, const char *key, void *value);
39 39 int hashset_remove(const HashSet *hm, const char *key); int hashset_remove(const HashSet *hm, const char *key);
40 40 void hashset_stat(const HashSet *hm); void hashset_stat(const HashSet *hm);
41 41
42 void hashset_destroy(const HashSet *hs);
42 void hashset_destroy(HashSet *hs);
43 43
44 44 #endif #endif

File src/include/hstr_favorites.h changed (mode: 100644) (index 99be08e..0ff47ba)
12 12
13 13 #include <stdlib.h> #include <stdlib.h>
14 14 #include <stdbool.h> #include <stdbool.h>
15 #include "hashset.h"
15 16
16 17 #define ENV_VAR_USER "USER" #define ENV_VAR_USER "USER"
17 18 #define ENV_VAR_HOME "HOME" #define ENV_VAR_HOME "HOME"
 
... ... typedef struct {
22 23 char **items; char **items;
23 24 unsigned count; unsigned count;
24 25 bool loaded; bool loaded;
26 HashSet *set;
25 27 } FavoriteItems; } FavoriteItems;
26 28
27 29 void favorites_init(FavoriteItems *favorites); void favorites_init(FavoriteItems *favorites);
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