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 diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index 0edf85e..c3e1467 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.