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 e0f194912c2c34c477e42570b85714943d6d42a3

Adding highlighting of keywords matching lines.
Author: Martin Dvorak
Author date (UTC): 2014-10-29 19:03
Committer name: Martin Dvorak
Committer date (UTC): 2014-10-29 19:03
Parent(s): f2ea910c7b1263b0a306558bc69e6d25769e8a46
Signing key:
Tree: ba4922d82767fb4a3eb399e3712b0d672c289c9c
File Lines added Lines deleted
src/hstr.c 28 11
File src/hstr.c changed (mode: 100644) (index e106d86..54be6d9)
... ... unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti
452 452 regmatch_t regexpMatch; regmatch_t regexpMatch;
453 453 char regexpErrorMessage[CMDLINE_LNG]; char regexpErrorMessage[CMDLINE_LNG];
454 454 bool regexpCompilationError=false; bool regexpCompilationError=false;
455 bool keywordsAllMatch;
456 char *keywordsSavePtr;
457 char *keywordsToken;
458 char *keywordsParsedLine;
455 bool keywordsAllMatch;
456 char *keywordsSavePtr;
457 char *keywordsToken;
458 char *keywordsParsedLine;
459 459 char *keywordsPointerToDelete; char *keywordsPointerToDelete;
460 460 for(i=0; i<count && selectionCount<maxSelectionCount; i++) { for(i=0; i<count && selectionCount<maxSelectionCount; i++) {
461 461 if(source[i]) { if(source[i]) {
 
... ... unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti
492 492 } }
493 493 break; break;
494 494 case HH_MATCH_KEYWORDS: case HH_MATCH_KEYWORDS:
495 // TODO: differentiate between case-sensitive and insensitive
495 // TODO differentiate between case-sensitive and insensitive
496 496 keywordsParsedLine = strdup(prefix); keywordsParsedLine = strdup(prefix);
497 keywordsAllMatch = true;
497 keywordsAllMatch = true;
498 498 keywordsPointerToDelete = keywordsParsedLine; keywordsPointerToDelete = keywordsParsedLine;
499 499 while (true) { while (true) {
500 500 keywordsToken = strtok_r(keywordsParsedLine, " ", &keywordsSavePtr); keywordsToken = strtok_r(keywordsParsedLine, " ", &keywordsSavePtr);
501 keywordsParsedLine = NULL;
501 keywordsParsedLine = NULL;
502 502 if (keywordsToken == NULL) { if (keywordsToken == NULL) {
503 503 break; break;
504 504 } }
505
506 505 if (strcasestr(source[i], keywordsToken) == NULL) { if (strcasestr(source[i], keywordsToken) == NULL) {
507 506 keywordsAllMatch = false; keywordsAllMatch = false;
508 507 } }
509 508 } }
510 if (keywordsAllMatch) {
509 if (keywordsAllMatch) {
511 510 hstr->selection[selectionCount++]=source[i]; hstr->selection[selectionCount++]=source[i];
512 511 } }
513 512 free(keywordsPointerToDelete); free(keywordsPointerToDelete);
 
... ... void print_selection_row(char *text, int y, int width, char *pattern)
561 560 if(pattern && strlen(pattern)) { if(pattern && strlen(pattern)) {
562 561 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
563 562 char *p; char *p;
563 bool keywordsAllMatch;
564 char *keywordsSavePtr;
565 char *keywordsToken;
566 char *keywordsParsedLine;
567 char *keywordsPointerToDelete;
564 568
565 569 switch(hstr->historyMatch) { switch(hstr->historyMatch) {
566 570 case HH_MATCH_SUBSTRING: case HH_MATCH_SUBSTRING:
 
... ... void print_selection_row(char *text, int y, int width, char *pattern)
581 585 mvprintw(y, 1+(p-text), "%s", pattern); mvprintw(y, 1+(p-text), "%s", pattern);
582 586 break; break;
583 587 case HH_MATCH_KEYWORDS: case HH_MATCH_KEYWORDS:
584 p=strstr(text, pattern);
585 mvprintw(y, 1+(p-text), "%s", pattern);
588 // TODO MD split pattern using space and highlight each segment
589 keywordsParsedLine = strdup(pattern);
590 keywordsAllMatch = true;
591 keywordsPointerToDelete = keywordsParsedLine;
592 while (true) {
593 keywordsToken = strtok_r(keywordsParsedLine, " ", &keywordsSavePtr);
594 keywordsParsedLine = NULL;
595 if (keywordsToken == NULL) {
596 break;
597 }
598 p=strstr(text, keywordsToken);
599 mvprintw(y, 1+(p-text), "%s", keywordsToken);
600 }
601 free(keywordsPointerToDelete);
602
586 603 break; break;
587 604 } }
588 605 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
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