fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

commit 5d8840288f99e76a9e144e530ce4c8adfede7bf0
parent 0e4ae2b032aa9a9b9cdbaab313e080ff4b4dfc5b
Author: John Hawthorn <john.hawthorn@gmail.com>
Date:   Sat, 26 Jul 2014 02:44:12 -0700

Don't require scores to be positive

Previously a successful match was determined by the score being
positive. Now we will use has_match instead.

Diffstat:
Mfzy.c | 4++--
Mfzy.h | 1+
Mmatch.c | 4++--
3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fzy.c b/fzy.c @@ -77,8 +77,8 @@ void run_search(char *needle){ choices_available = 0; int i; for(i = 0; i < choices_n; i++){ - choices_score[i] = match(needle, choices[i]); - if(choices_score[i] >= 0.0){ + if(has_match(needle, choices[i])){ + choices_score[i] = match(needle, choices[i]); choices_sorted[choices_available++] = i; } } diff --git a/fzy.h b/fzy.h @@ -1,6 +1,7 @@ #ifndef FZY_H #define FZY_H FZY_H +int has_match(const char *needle, const char *haystack); double match_positions(const char *needle, const char *haystack, size_t *positions); double match(const char *needle, const char *haystack); diff --git a/match.c b/match.c @@ -7,7 +7,7 @@ #define SCORE_MIN -1 -static int is_subset(const char *needle, const char *haystack){ +int has_match(const char *needle, const char *haystack){ while(*needle){ if(!*haystack) return 0; @@ -115,7 +115,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio double match_positions(const char *needle, const char *haystack, size_t *positions){ if(!*needle){ return 1.0; - }else if(!is_subset(needle, haystack)){ + }else if(!has_match(needle, haystack)){ return SCORE_MIN; }else if(!strcasecmp(needle, haystack)){ if(positions){