From 3f8e85f3f8d676f2156849755b29a24cc82ac28a Mon Sep 17 00:00:00 2001 From: Part Cyborg Date: Mon, 1 Oct 2018 05:11:52 -0700 Subject: [PATCH 1/2] Support anchoring the substring to search for Add a new config variable that will anchor the history search to the beginning of the command. Note that the default behavior does not change with this --- zsh-history-substring-search.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index 0edf85e..a0f3af9 100644 --- a/zsh-history-substring-search.zsh +++ b/zsh-history-substring-search.zsh @@ -246,7 +246,13 @@ _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}*" + # + # Support anchoring history search to the beginning of the command + # + if [[ -z $HISTORY_SUBSTRING_SEARCH_ANCHORED ]]; then + search_pattern="*${search_pattern}" + fi # # Find all occurrences of the search pattern in the history file. From f48193bcd9d7bb4845c1502be5edbdc214f8c2e4 Mon Sep 17 00:00:00 2001 From: Part Cyborg Date: Fri, 3 Jul 2020 15:57:16 -0700 Subject: [PATCH 2/2] Declare HISTORY_SUBSTRING_SEARCH_ANCHORED global --- zsh-history-substring-search.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh index a0f3af9..3b40696 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_ANCHORED='' #----------------------------------------------------------------------------- # declare internal global variables