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 934c5b14d5938d1f0ac0248b6a6136d3cfb470fc

More #129 related fixes - in certain situations garbage still present :-/
Author: Martin Dvorak
Author date (UTC): 2015-02-23 08:48
Committer name: Martin Dvorak
Committer date (UTC): 2015-02-23 08:48
Parent(s): e50573964d7b2dd5e21e6426fc48514ab20d68cb
Signing key:
Tree: 91d4d4ed1c4a585da3ca2315046163ad59ef0e7e
File Lines added Lines deleted
src/hstr.c 13 27
src/hstr_history.c 22 15
src/include/hstr_history.h 2 1
File src/hstr.c changed (mode: 100644) (index ce97246..6c501ca)
... ... void highlight_selection(int selectionCursorPosition, int previousSelectionCurso
729 729 } }
730 730 } }
731 731
732 void selection_remove(char *cmd, Hstr *hstr)
733 {
734 if(hstr->historyView==HH_VIEW_FAVORITES) {
735 favorites_remove(hstr->favorites, cmd);
736 } else {
737 if(hstr->history->count) {
738 int i, w;
739 for(i=0, w=0; i<hstr->history->count; i++) {
740 if(strcmp(hstr->history->items[i], cmd)) {
741 hstr->history->items[w]=hstr->history->items[i];
742 w++;
743 }
744 }
745 hstr->history->count=w;
746 }
747 }
748 }
749
750 732 void hstr_on_exit(Hstr *hstr) void hstr_on_exit(Hstr *hstr)
751 733 { {
752 734 history_mgmt_flush(); history_mgmt_flush();
 
... ... void signal_callback_handler_ctrl_c(int signum)
762 744 } }
763 745 } }
764 746
765 int seletion_source_remove(char *delete, Hstr *hstr)
747 int remove_from_history_model(char *delete, Hstr *hstr)
766 748 { {
767 if(hstr->historyView!=HH_VIEW_FAVORITES) {
768 // raw history is pruned first as its items point to system history lines (freed right after)
769 int systemOccurences, rawOccurences=history_mgmt_remove_from_hh_raw(delete, hstr->history);
749 if(hstr->historyView==HH_VIEW_FAVORITES) {
750 return favorites_remove(hstr->favorites, delete);
751 } else {
752 // raw & ranked history is pruned first as its items point to system history lines
753 int systemOccurences, rawOccurences=history_mgmt_remove_from_raw(delete, hstr->history);
754 history_mgmt_remove_from_ranked(delete, hstr->history);
770 755 if(rawOccurences) { if(rawOccurences) {
771 756 systemOccurences=history_mgmt_remove_from_system_history(delete); systemOccurences=history_mgmt_remove_from_system_history(delete);
772 757 } }
 
... ... int seletion_source_remove(char *delete, Hstr *hstr)
774 759 fprintf(stderr, "WARNING: system and raw items deletion mismatch %d / %d\n", systemOccurences, rawOccurences); fprintf(stderr, "WARNING: system and raw items deletion mismatch %d / %d\n", systemOccurences, rawOccurences);
775 760 } }
776 761 return systemOccurences; return systemOccurences;
777 } else {
778 return favorites_remove(hstr->favorites, delete);
779 762 } }
780 763 } }
781 764
 
... ... void loop_to_select(Hstr *hstr)
855 838
856 839 switch (c) { switch (c) {
857 840 case KEY_DC: // DEL case KEY_DC: // DEL
841 // TODO verification - still broken:
842 // > use 3 items history configuration
843 // > delete 2nd item in raw view > blank line
844 // > delete one of items in raw view > garbage
858 845 if(selectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT) { if(selectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT) {
859 846 delete=hstr->selection[selectionCursorPosition]; delete=hstr->selection[selectionCursorPosition];
860 847 msg=malloc(strlen(delete)+1); msg=malloc(strlen(delete)+1);
861 848 strcpy(msg,delete); strcpy(msg,delete);
862 selection_remove(delete, hstr);
863 deletedOccurences=seletion_source_remove(delete, hstr);
849 deletedOccurences=remove_from_history_model(delete, hstr);
864 850 result=hstr_print_selection(maxHistoryItems, pattern, hstr); result=hstr_print_selection(maxHistoryItems, pattern, hstr);
865 851 print_cmd_deleted_label(msg, deletedOccurences, hstr); print_cmd_deleted_label(msg, deletedOccurences, hstr);
866 852 move(y, basex+strlen(pattern)); move(y, basex+strlen(pattern));
867 853 printDefaultLabel=TRUE; printDefaultLabel=TRUE;
854 print_history_label(hstr);
868 855 } }
869 print_history_label(hstr);
870 856 // TODO new code - coredump on view rotation // TODO new code - coredump on view rotation
871 857 // highlight_selection(selectionCursorPosition, previousSelectionCursorPosition, pattern, hstr); // highlight_selection(selectionCursorPosition, previousSelectionCursorPosition, pattern, hstr);
872 858 // move(y, basex+strlen(pattern)); // move(y, basex+strlen(pattern));
File src/hstr_history.c changed (mode: 100644) (index 51385f9..2b1dd4e)
... ... int history_mgmt_remove_from_system_history(char *cmd)
230 230 return occurences; return occurences;
231 231 } }
232 232
233 int history_mgmt_remove_from_hh_raw(char *cmd, HistoryItems *historyItems) {
234 int delta=0;
235 if(historyItems->rawCount) {
236 int i, newRawCount=historyItems->rawCount;
237 for(i=0; i<historyItems->rawCount; i++) {
238 if(!strcmp(cmd, historyItems->rawItems[i])) {
239 delta++;
240 historyItems->rawItems[i-delta]=historyItems->rawItems[i];
241 } else {
242 if(delta) {
243 historyItems->rawItems[i-delta]=historyItems->rawItems[i];
244 }
233 int history_mgmt_remove_from_raw(char *cmd, HistoryItems *history) {
234 int occurences=history->rawCount;
235 if(history->rawCount) {
236 int i, ii;
237 for(i=0, ii=0; i<history->rawCount; i++) {
238 if(strcmp(cmd, history->rawItems[i])) {
239 history->rawItems[ii++]=history->rawItems[i];
245 240 } }
246 241 } }
247 if(delta) {
248 historyItems->rawCount-=delta;
242 history->rawCount=ii;
243 }
244 return occurences-history->rawCount;
245 }
246
247 int history_mgmt_remove_from_ranked(char *cmd, HistoryItems *history) {
248 int occurences=history->count;
249 if(history->count) {
250 int i, ii;
251 for(i=0, ii=0; i<history->count; i++) {
252 if(strcmp(cmd, history->items[i])) {
253 history->items[ii++]=history->items[i];
254 }
249 255 } }
256 history->count=ii;
250 257 } }
251 return delta;
258 return occurences-history->count;
252 259 } }
253 260
254 261 void history_mgmt_flush() void history_mgmt_flush()
File src/include/hstr_history.h changed (mode: 100644) (index f52894e..a2e2528)
... ... void free_prioritized_history();
51 51 void history_mgmt_open(); void history_mgmt_open();
52 52 void history_clear_dirty(); void history_clear_dirty();
53 53 int history_mgmt_remove_from_system_history(char *cmd); int history_mgmt_remove_from_system_history(char *cmd);
54 int history_mgmt_remove_from_hh_raw(char *cmd, HistoryItems *historyItems);
54 int history_mgmt_remove_from_raw(char *cmd, HistoryItems *history);
55 int history_mgmt_remove_from_ranked(char *cmd, HistoryItems *history);
55 56 void history_mgmt_flush(); void history_mgmt_flush();
56 57
57 58 #endif #endif
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