diff --git a/README.md b/README.md index 77f3649..5f58ba2 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,12 @@ default values only after having loaded this script into your ZSH session. 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_PREFIX` is a global variable that defines + how the command history will be searched for your query. If set to a non-empty + value, only history prefixed by your query will be matched. For example, + if this variable is empty, `ls` will match `ls -l` and `echo ls`; if it is + non-empty, `ls` will only match `ls -l`. + * `HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE` is a global variable that defines whether all search results returned are _unique_. If set to a non-empty value, then only unique search results are presented. This behaviour is off diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index a791cc4..7e72994 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -48,6 +48,7 @@ typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold' typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE='' typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY='' +typeset -g HISTORY_SUBSTRING_SEARCH_PREFIX='' #----------------------------------------------------------------------------- # declare internal global variables @@ -246,7 +247,8 @@ _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}*" + local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + test -z "$HISTORY_SUBSTRING_SEARCH_PREFIX" && search_pattern="*$search_pattern" # # Find all occurrences of the search pattern in the history file.