Skip to content

Commit 4abed97

Browse files
committed
Merge pull request #97 from partcyborg/master
Also rename `HISTORY_SUBSTRING_SEARCH_PREFIX` variable by adding "ED" suffix so that it reads more like a special mode of operation rather than an instruction to prepend a specified prefix to matched commands.
2 parents e310a75 + f48193b commit 4abed97

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ default values.
141141
value, causes this script to perform a fuzzy search by words, matching in
142142
given order e.g. `ab c` will match `*ab*c*`
143143

144-
* `HISTORY_SUBSTRING_SEARCH_PREFIX` is a global variable that defines
145-
how the command history will be searched for your query. If set to a non-empty
146-
value, only history prefixed by your query will be matched. For example,
147-
if this variable is empty, `ls` will match `ls -l` and `echo ls`; if it is
148-
non-empty, `ls` will only match `ls -l`.
144+
* `HISTORY_SUBSTRING_SEARCH_PREFIXED` is a global variable that defines how
145+
the command history will be searched for your query. If set to a non-empty
146+
value, your query will be matched against the start of each history entry.
147+
For example, if this variable is empty, `ls` will match `ls -l` and `echo
148+
ls`; if it is non-empty, `ls` will only match `ls -l`.
149149

150150
* `HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE` is a global variable that defines
151151
whether all search results returned are _unique_. If set to a non-empty

zsh-history-substring-search.zsh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
: ${HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'}
4949
: ${HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''}
5050
: ${HISTORY_SUBSTRING_SEARCH_FUZZY=''}
51-
: ${HISTORY_SUBSTRING_SEARCH_PREFIX=''}
51+
: ${HISTORY_SUBSTRING_SEARCH_PREFIXED=''}
5252

5353
#-----------------------------------------------------------------------------
5454
# declare internal global variables
@@ -248,7 +248,13 @@ _history-substring-search-begin() {
248248
# `(j:CHAR:)` join array to string with CHAR as seperator
249249
#
250250
local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
251-
test -z "$HISTORY_SUBSTRING_SEARCH_PREFIX" && search_pattern="*$search_pattern"
251+
252+
#
253+
# Support anchoring history search to the beginning of the command
254+
#
255+
if [[ -z $HISTORY_SUBSTRING_SEARCH_PREFIXED ]]; then
256+
search_pattern="*${search_pattern}"
257+
fi
252258

253259
#
254260
# Find all occurrences of the search pattern in the history file.

0 commit comments

Comments
 (0)