Skip to content

Commit 3f8e85f

Browse files
committed
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
1 parent 47a7d41 commit 3f8e85f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

zsh-history-substring-search.zsh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,13 @@ _history-substring-search-begin() {
246246
# Escape and join query parts with wildcard character '*' as seperator
247247
# `(j:CHAR:)` join array to string with CHAR as seperator
248248
#
249-
local search_pattern="*${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
249+
local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
250+
#
251+
# Support anchoring history search to the beginning of the command
252+
#
253+
if [[ -z $HISTORY_SUBSTRING_SEARCH_ANCHORED ]]; then
254+
search_pattern="*${search_pattern}"
255+
fi
250256

251257
#
252258
# Find all occurrences of the search pattern in the history file.

0 commit comments

Comments
 (0)