mirror of
https://github.com/zsh-users/zsh-history-substring-search.git
synced 2026-11-11 11:41:49 -05:00
add HISTORY_SUBSTRING_SEARCH_PREFIX (#112,#115)
* `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`. Co-authored-by: Xue Qianming <qianmingxue@microsoft.com>
This commit is contained in:
co-authored by
Xue Qianming
parent
0f80b8eb33
commit
4f2f17cc46
@@ -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
|
value, causes this script to perform a fuzzy search by words, matching in
|
||||||
given order e.g. `ab c` will match `*ab*c*`
|
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
|
* `HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE` is a global variable that defines
|
||||||
whether all search results returned are _unique_. If set to a non-empty
|
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
|
value, then only unique search results are presented. This behaviour is off
|
||||||
|
|||||||
@@ -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_GLOBBING_FLAGS='i'
|
||||||
typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''
|
typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''
|
||||||
typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY=''
|
typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY=''
|
||||||
|
typeset -g HISTORY_SUBSTRING_SEARCH_PREFIX=''
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# declare internal global variables
|
# declare internal global variables
|
||||||
@@ -246,7 +247,8 @@ _history-substring-search-begin() {
|
|||||||
# Escape and join query parts with wildcard character '*' as seperator
|
# Escape and join query parts with wildcard character '*' as seperator
|
||||||
# `(j:CHAR:)` join array to string with CHAR 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.
|
# Find all occurrences of the search pattern in the history file.
|
||||||
|
|||||||
Reference in New Issue
Block a user