From b8a1292a11a27c3d6ff23117ac51031efad2dc2a Mon Sep 17 00:00:00 2001 From: sephv Date: Tue, 19 Jun 2018 14:30:45 -0400 Subject: [PATCH 1/3] Allow fuzzy search to match after cursor position --- zsh-history-substring-search.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index 0edf85e..f922b1a 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -246,7 +246,11 @@ _history-substring-search-begin() { # Escape and join query parts with wildcard character '*' as seperator # `(j:CHAR:)` join array to string with CHAR as seperator # - local search_pattern="*${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + if [[ -z $HISTORY_SUBSTRING_SEARCH_FUZZY_AFTER_CURSOR ]]; then + local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + else + local search_pattern="*${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + fi # # Find all occurrences of the search pattern in the history file. From 0f04f6edcdafb3e2ae30501ceef33a442565a92f Mon Sep 17 00:00:00 2001 From: sephv Date: Tue, 19 Jun 2018 14:32:25 -0400 Subject: [PATCH 2/3] Update zsh-history-substring-search.zsh --- zsh-history-substring-search.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index f922b1a..c3e1467 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -247,10 +247,10 @@ _history-substring-search-begin() { # `(j:CHAR:)` join array to string with CHAR as seperator # if [[ -z $HISTORY_SUBSTRING_SEARCH_FUZZY_AFTER_CURSOR ]]; then - local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" - else - local search_pattern="*${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" - fi + local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + else + local search_pattern="*${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + fi # # Find all occurrences of the search pattern in the history file. From 5c391f65dc6346edefda3cf94f613adabec6b103 Mon Sep 17 00:00:00 2001 From: sephv Date: Tue, 19 Jun 2018 14:40:13 -0400 Subject: [PATCH 3/3] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index c9dbad6..c4c5ad1 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,11 @@ default values only after having loaded this script into your ZSH session. how the command history will be searched for your query. If set to a non-empty value, causes this script to perform a fuzzy search by words, matching in given order e.g. `ab c` will match `*ab*c*` + +* `HISTORY_SUBSTRING_SEARCH_FUZZY_AFTER_CURSOR` will allow fuzzy searching, if + enabled, to begin fuzzy matching after the cursor position and use literal + matching for the characters before the cursor position e.g if cursor comes + after the `c` in `abc` will match `abc*` instead of `*abc*` * `HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE` is a global variable that defines whether all search results returned are _unique_. If set to a non-empty