Skip to content

Commit

Permalink
Merge pull request #97 from partcyborg/master
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sunaku committed Aug 3, 2021
2 parents e310a75 + f48193b commit 4abed97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ default values.
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_PREFIXED` is a global variable that defines how
the command history will be searched for your query. If set to a non-empty
value, your query will be matched against the start of each history entry.
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
Expand Down
10 changes: 8 additions & 2 deletions zsh-history-substring-search.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
: ${HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'}
: ${HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''}
: ${HISTORY_SUBSTRING_SEARCH_FUZZY=''}
: ${HISTORY_SUBSTRING_SEARCH_PREFIX=''}
: ${HISTORY_SUBSTRING_SEARCH_PREFIXED=''}

#-----------------------------------------------------------------------------
# declare internal global variables
Expand Down Expand Up @@ -248,7 +248,13 @@ _history-substring-search-begin() {
# `(j:CHAR:)` join array to string with CHAR as seperator
#
local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
test -z "$HISTORY_SUBSTRING_SEARCH_PREFIX" && search_pattern="*$search_pattern"

#
# Support anchoring history search to the beginning of the command
#
if [[ -z $HISTORY_SUBSTRING_SEARCH_PREFIXED ]]; then
search_pattern="*${search_pattern}"
fi

#
# Find all occurrences of the search pattern in the history file.
Expand Down

0 comments on commit 4abed97

Please sign in to comment.