2 ##############################################################################
4 # Copyright (c) 2009 Peter Stephenson
5 # Copyright (c) 2011 Guido van Steen
6 # Copyright (c) 2011 Suraj N. Kurapati
7 # Copyright (c) 2011 Sorin Ionescu
8 # Copyright (c) 2011 Vincent Guerci
9 # Copyright (c) 2016 Geza Lore
10 # Copyright (c) 2017 Bengt Brodersen
11 # All rights reserved.
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions are met:
16 # * Redistributions of source code must retain the above copyright
17 # notice, this list of conditions and the following disclaimer.
19 # * Redistributions in binary form must reproduce the above
20 # copyright notice, this list of conditions and the following
21 # disclaimer in the documentation and/or other materials provided
22 # with the distribution.
24 # * Neither the name of the FIZSH nor the names of its contributors
25 # may be used to endorse or promote products derived from this
26 # software without specific prior written permission.
28 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
32 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 # POSSIBILITY OF SUCH DAMAGE.
40 ##############################################################################
42 #-----------------------------------------------------------------------------
43 # declare global configuration variables
44 #-----------------------------------------------------------------------------
46 typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold'
47 typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold'
48 typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'
49 typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''
50 typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY=''
52 #-----------------------------------------------------------------------------
53 # declare internal global variables
54 #-----------------------------------------------------------------------------
56 typeset -g BUFFER MATCH MBEGIN MEND CURSOR
57 typeset -g _history_substring_search_refresh_display
58 typeset -g _history_substring_search_query_highlight
59 typeset -g _history_substring_search_result
60 typeset -g _history_substring_search_query
61 typeset -g -a _history_substring_search_query_parts
62 typeset -g -a _history_substring_search_raw_matches
63 typeset -g -i _history_substring_search_raw_match_index
64 typeset -g -a _history_substring_search_matches
65 typeset -g -i _history_substring_search_match_index
66 typeset -g -A _history_substring_search_unique_filter
68 #-----------------------------------------------------------------------------
69 # the main ZLE widgets
70 #-----------------------------------------------------------------------------
72 history-substring-search-up() {
73 _history-substring-search-begin
75 _history-substring-search-up-history ||
76 _history-substring-search-up-buffer ||
77 _history-substring-search-up-search
79 _history-substring-search-end
82 history-substring-search-down() {
83 _history-substring-search-begin
85 _history-substring-search-down-history ||
86 _history-substring-search-down-buffer ||
87 _history-substring-search-down-search
89 _history-substring-search-end
92 zle -N history-substring-search-up
93 zle -N history-substring-search-down
95 #-----------------------------------------------------------------------------
96 # implementation details
97 #-----------------------------------------------------------------------------
99 zmodload -F zsh/parameter
102 # We have to "override" some keys and widgets if the
103 # zsh-syntax-highlighting plugin has not been loaded:
105 # https://github.com/nicoulaj/zsh-syntax-highlighting
107 if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
109 # Dummy implementation of _zsh_highlight() that
110 # simply removes any existing highlights when the
111 # user inserts printable characters into $BUFFER.
114 if [[ $KEYS == [[:print:]] ]]; then
120 # The following snippet was taken from the zsh-syntax-highlighting project:
122 # https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161
124 # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
125 # All rights reserved.
127 # Redistribution and use in source and binary forms, with or without
128 # modification, are permitted provided that the following conditions are
131 # * Redistributions of source code must retain the above copyright
132 # notice, this list of conditions and the following disclaimer.
134 # * Redistributions in binary form must reproduce the above copyright
135 # notice, this list of conditions and the following disclaimer in the
136 # documentation and/or other materials provided with the distribution.
138 # * Neither the name of the zsh-syntax-highlighting contributors nor the
139 # names of its contributors may be used to endorse or promote products
140 # derived from this software without specific prior written permission.
142 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
143 # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
144 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
145 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
146 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
147 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
148 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
149 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
150 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
151 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
152 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
154 #--------------8<-------------------8<-------------------8<-----------------
155 # Rebind all ZLE widgets to make them invoke _zsh_highlights.
156 _zsh_highlight_bind_widgets()
158 # Load ZSH module zsh/zleparameter, needed to override user defined widgets.
159 zmodload zsh/zleparameter 2>/dev/null || {
160 echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
164 # Override ZLE widgets to make them invoke _zsh_highlight.
166 for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do
167 case $widgets[$cur_widget] in
169 # Already rebound event: do nothing.
170 user:$cur_widget|user:_zsh_highlight_widget_*);;
172 # User defined widget: override and rebind old one with prefix "orig-".
173 user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \
174 _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
175 zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
177 # Completion widget: override and rebind old one with prefix "orig-".
178 completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \
179 _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
180 zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
182 # Builtin widget: override and make it call the builtin ".widget".
183 builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \
184 zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
186 # Default: unhandled case.
187 *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;;
191 #-------------->8------------------->8------------------->8-----------------
193 _zsh_highlight_bind_widgets
196 _history-substring-search-begin() {
197 setopt localoptions extendedglob
199 _history_substring_search_refresh_display=
200 _history_substring_search_query_highlight=
203 # If the buffer is the same as the previously displayed history substring
204 # search result, then just keep stepping through the match list. Otherwise
205 # start a new search.
207 if [[ -n $BUFFER && $BUFFER == ${_history_substring_search_result:-} ]]; then
212 # Clear the previous result.
214 _history_substring_search_result=''
216 if [[ -z $BUFFER ]]; then
218 # If the buffer is empty, we will just act like up-history/down-history
219 # in ZSH, so we do not need to actually search the history. This should
220 # speed things up a little.
222 _history_substring_search_query=
223 _history_substring_search_query_parts=()
224 _history_substring_search_raw_matches=()
228 # For the purpose of highlighting we keep a copy of the original
231 _history_substring_search_query=$BUFFER
234 # compose search pattern
236 if [[ -n $HISTORY_SUBSTRING_SEARCH_FUZZY ]]; then
238 # `=` split string in arguments
240 _history_substring_search_query_parts=(${=_history_substring_search_query})
242 _history_substring_search_query_parts=(${==_history_substring_search_query})
246 # Escape and join query parts with wildcard character '*' as separator
247 # `(j:CHAR:)` join array to string with CHAR as separator
249 local search_pattern="*${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
252 # Find all occurrences of the search pattern in the history file.
254 # (k) returns the "keys" (history index numbers) instead of the values
255 # (R) returns values in reverse older, so the index of the youngest
256 # matching history entry is at the head of the list.
258 _history_substring_search_raw_matches=(${(k)history[(R)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)${search_pattern}]})
262 # In order to stay as responsive as possible, we will process the raw
263 # matches lazily (when the user requests the next match) to choose items
264 # that need to be displayed to the user.
265 # _history_substring_search_raw_match_index holds the index of the last
266 # unprocessed entry in _history_substring_search_raw_matches. Any items
267 # that need to be displayed will be added to
268 # _history_substring_search_matches.
270 # We use an associative array (_history_substring_search_unique_filter) as
271 # a 'set' data structure to ensure uniqueness of the results if desired.
272 # If an entry (key) is in the set (non-empty value), then we have already
273 # added that entry to _history_substring_search_matches.
275 _history_substring_search_raw_match_index=0
276 _history_substring_search_matches=()
277 _history_substring_search_unique_filter=()
280 # If $_history_substring_search_match_index is equal to
281 # $#_history_substring_search_matches + 1, this indicates that we
282 # are beyond the end of $_history_substring_search_matches and that we
283 # have also processed all entries in
284 # _history_substring_search_raw_matches.
286 # If $#_history_substring_search_match_index is equal to 0, this indicates
287 # that we are beyond the beginning of $_history_substring_search_matches.
289 # If we have initially pressed "up" we have to initialize
290 # $_history_substring_search_match_index to 0 so that it will be
293 # If we have initially pressed "down" we have to initialize
294 # $_history_substring_search_match_index to 1 so that it will be
297 if [[ $WIDGET == history-substring-search-down ]]; then
298 _history_substring_search_match_index=1
300 _history_substring_search_match_index=0
304 _history-substring-search-end() {
305 setopt localoptions extendedglob
307 _history_substring_search_result=$BUFFER
309 # the search was successful so display the result properly by clearing away
310 # existing highlights and moving the cursor to the end of the result buffer
311 if [[ $_history_substring_search_refresh_display -eq 1 ]]; then
316 # highlight command line using zsh-syntax-highlighting
319 # highlight the search query inside the command line
320 if [[ -n $_history_substring_search_query_highlight ]]; then
321 # highlight first matching query parts
322 local highlight_start_index=0
323 local highlight_end_index=0
325 for query_part in $_history_substring_search_query_parts; do
326 local escaped_query_part=${query_part//(#m)[\][()|\\*?#<>~^]/\\$MATCH}
327 # (i) get index of pattern
328 local query_part_match_index="${${BUFFER:$highlight_start_index}[(i)(#$HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS)${escaped_query_part}]}"
329 if [[ $query_part_match_index -le ${#BUFFER:$highlight_start_index} ]]; then
330 highlight_start_index=$(( $highlight_start_index + $query_part_match_index ))
331 highlight_end_index=$(( $highlight_start_index + ${#query_part} ))
332 region_highlight+=("$(($highlight_start_index - 1)) $(($highlight_end_index - 1)) $_history_substring_search_query_highlight")
337 # For debugging purposes:
338 # zle -R "mn: "$_history_substring_search_match_index" m#: "${#_history_substring_search_matches}
339 # read -k -t 200 && zle -U $REPLY
341 # Exit successfully from the history-substring-search-* widgets.
345 _history-substring-search-up-buffer() {
347 # Check if the UP arrow was pressed to move the cursor within a multi-line
348 # buffer. This amounts to three tests:
350 # 1. $#buflines -gt 1.
352 # 2. $CURSOR -ne $#BUFFER.
354 # 3. Check if we are on the first line of the current multi-line buffer.
355 # If so, pressing UP would amount to leaving the multi-line buffer.
357 # We check this by adding an extra "x" to $LBUFFER, which makes
358 # sure that xlbuflines is always equal to the number of lines
359 # until $CURSOR (including the line with the cursor on it).
361 local buflines XLBUFFER xlbuflines
362 buflines=(${(f)BUFFER})
364 xlbuflines=(${(f)XLBUFFER})
366 if [[ $#buflines -gt 1 && $CURSOR -ne $#BUFFER && $#xlbuflines -ne 1 ]]; then
367 zle up-line-or-history
374 _history-substring-search-down-buffer() {
376 # Check if the DOWN arrow was pressed to move the cursor within a multi-line
377 # buffer. This amounts to three tests:
379 # 1. $#buflines -gt 1.
381 # 2. $CURSOR -ne $#BUFFER.
383 # 3. Check if we are on the last line of the current multi-line buffer.
384 # If so, pressing DOWN would amount to leaving the multi-line buffer.
386 # We check this by adding an extra "x" to $RBUFFER, which makes
387 # sure that xrbuflines is always equal to the number of lines
388 # from $CURSOR (including the line with the cursor on it).
390 local buflines XRBUFFER xrbuflines
391 buflines=(${(f)BUFFER})
393 xrbuflines=(${(f)XRBUFFER})
395 if [[ $#buflines -gt 1 && $CURSOR -ne $#BUFFER && $#xrbuflines -ne 1 ]]; then
396 zle down-line-or-history
403 _history-substring-search-up-history() {
405 # Behave like up in ZSH, except clear the $BUFFER
406 # when beginning of history is reached like in Fish.
408 if [[ -z $_history_substring_search_query ]]; then
410 # we have reached the absolute top of history
411 if [[ $HISTNO -eq 1 ]]; then
414 # going up from somewhere below the top of history
416 zle up-line-or-history
425 _history-substring-search-down-history() {
427 # Behave like down-history in ZSH, except clear the
428 # $BUFFER when end of history is reached like in Fish.
430 if [[ -z $_history_substring_search_query ]]; then
432 # going down from the absolute top of history
433 if [[ $HISTNO -eq 1 && -z $BUFFER ]]; then
435 _history_substring_search_refresh_display=1
437 # going down from somewhere above the bottom of history
439 zle down-line-or-history
448 _history_substring_search_process_raw_matches() {
450 # Process more outstanding raw matches and append any matches that need to
451 # be displayed to the user to _history_substring_search_matches.
452 # Return whether there were any more results appended.
456 # While we have more raw matches. Process them to see if there are any more
457 # matches that need to be displayed to the user.
459 while [[ $_history_substring_search_raw_match_index -lt $#_history_substring_search_raw_matches ]]; do
461 # Move on to the next raw entry and get its history index.
463 _history_substring_search_raw_match_index+=1
464 local index=${_history_substring_search_raw_matches[$_history_substring_search_raw_match_index]}
467 # If HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is set to a non-empty value,
468 # then ensure that only unique matches are presented to the user.
469 # When HIST_IGNORE_ALL_DUPS is set, ZSH already ensures a unique history,
470 # so in this case we do not need to do anything.
472 if [[ ! -o HIST_IGNORE_ALL_DUPS && -n $HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE ]]; then
474 # Get the actual history entry at the new index, and check if we have
475 # already added it to _history_substring_search_matches.
477 local entry=${history[$index]}
479 if [[ -z ${_history_substring_search_unique_filter[$entry]} ]]; then
481 # This is a new unique entry. Add it to the filter and append the
482 # index to _history_substring_search_matches.
484 _history_substring_search_unique_filter[$entry]=1
485 _history_substring_search_matches+=($index)
488 # Indicate that we did find a match.
495 # Just append the new history index to the processed matches.
497 _history_substring_search_matches+=($index)
500 # Indicate that we did find a match.
508 # We are beyond the end of the list of raw matches. Indicate that no
509 # more matches are available.
514 _history-substring-search-has-next() {
516 # Predicate function that returns whether any more older matches are
520 if [[ $_history_substring_search_match_index -lt $#_history_substring_search_matches ]]; then
522 # We did not reach the end of the processed list, so we do have further
529 # We are at the end of the processed list. Try to process further
530 # unprocessed matches. _history_substring_search_process_raw_matches
531 # returns whether any more matches were available, so just return
534 _history_substring_search_process_raw_matches
539 _history-substring-search-has-prev() {
541 # Predicate function that returns whether any more younger matches are
545 if [[ $_history_substring_search_match_index -gt 1 ]]; then
547 # We did not reach the beginning of the processed list, so we do have
554 # We are at the beginning of the processed list. We do not have any more
561 _history-substring-search-found() {
563 # A match is available. The index of the match is held in
564 # $_history_substring_search_match_index
566 # 1. Make $BUFFER equal to the matching history entry.
568 # 2. Use $HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND
569 # to highlight the current buffer.
571 BUFFER=$history[$_history_substring_search_matches[$_history_substring_search_match_index]]
572 _history_substring_search_query_highlight=$HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND
575 _history-substring-search-not-found() {
577 # No more matches are available.
579 # 1. Make $BUFFER equal to $_history_substring_search_query so the user can
580 # revise it and search again.
582 # 2. Use $HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND
583 # to highlight the current buffer.
585 BUFFER=$_history_substring_search_query
586 _history_substring_search_query_highlight=$HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND
589 _history-substring-search-up-search() {
590 _history_substring_search_refresh_display=1
593 # Select history entry during history-substring-down-search:
595 # The following variables have been initialized in
596 # _history-substring-search-up/down-search():
598 # $_history_substring_search_matches is the current list of matches that
599 # need to be displayed to the user.
600 # $_history_substring_search_match_index is the index of the current match
601 # that is being displayed to the user.
603 # The range of values that $_history_substring_search_match_index can take
604 # is: [0, $#_history_substring_search_matches + 1]. A value of 0
605 # indicates that we are beyond the beginning of
606 # $_history_substring_search_matches. A value of
607 # $#_history_substring_search_matches + 1 indicates that we are beyond
608 # the end of $_history_substring_search_matches and that we have also
609 # processed all entries in _history_substring_search_raw_matches.
611 # If $_history_substring_search_match_index equals
612 # $#_history_substring_search_matches and
613 # $_history_substring_search_raw_match_index is not greater than
614 # $#_history_substring_search_raw_matches, then we need to further process
615 # $_history_substring_search_raw_matches to see if there are any more
616 # entries that need to be displayed to the user.
618 # In _history-substring-search-up-search() the initial value of
619 # $_history_substring_search_match_index is 0. This value is set in
620 # _history-substring-search-begin(). _history-substring-search-up-search()
621 # will initially increment it to 1.
624 if [[ $_history_substring_search_match_index -gt $#_history_substring_search_matches ]]; then
626 # We are beyond the end of $_history_substring_search_matches. This
627 # can only happen if we have also exhausted the unprocessed matches in
628 # _history_substring_search_raw_matches.
630 # 1. Update display to indicate search not found.
632 _history-substring-search-not-found
636 if _history-substring-search-has-next; then
638 # We do have older matches.
640 # 1. Move index to point to the next match.
641 # 2. Update display to indicate search found.
643 _history_substring_search_match_index+=1
644 _history-substring-search-found
648 # We do not have older matches.
650 # 1. Move the index beyond the end of
651 # _history_substring_search_matches.
652 # 2. Update display to indicate search not found.
654 _history_substring_search_match_index+=1
655 _history-substring-search-not-found
659 # When HIST_FIND_NO_DUPS is set, meaning that only unique command lines from
660 # history should be matched, make sure the new and old results are different.
662 # However, if the HIST_IGNORE_ALL_DUPS shell option, or
663 # HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is set, then we already have a
664 # unique history, so in this case we do not need to do anything.
666 if [[ -o HIST_IGNORE_ALL_DUPS || -n $HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE ]]; then
670 if [[ -o HIST_FIND_NO_DUPS && $BUFFER == $_history_substring_search_result ]]; then
672 # Repeat the current search so that a different (unique) match is found.
674 _history-substring-search-up-search
678 _history-substring-search-down-search() {
679 _history_substring_search_refresh_display=1
682 # Select history entry during history-substring-down-search:
684 # The following variables have been initialized in
685 # _history-substring-search-up/down-search():
687 # $_history_substring_search_matches is the current list of matches that
688 # need to be displayed to the user.
689 # $_history_substring_search_match_index is the index of the current match
690 # that is being displayed to the user.
692 # The range of values that $_history_substring_search_match_index can take
693 # is: [0, $#_history_substring_search_matches + 1]. A value of 0
694 # indicates that we are beyond the beginning of
695 # $_history_substring_search_matches. A value of
696 # $#_history_substring_search_matches + 1 indicates that we are beyond
697 # the end of $_history_substring_search_matches and that we have also
698 # processed all entries in _history_substring_search_raw_matches.
700 # In _history-substring-search-down-search() the initial value of
701 # $_history_substring_search_match_index is 1. This value is set in
702 # _history-substring-search-begin(). _history-substring-search-down-search()
703 # will initially decrement it to 0.
706 if [[ $_history_substring_search_match_index -lt 1 ]]; then
708 # We are beyond the beginning of $_history_substring_search_matches.
710 # 1. Update display to indicate search not found.
712 _history-substring-search-not-found
716 if _history-substring-search-has-prev; then
718 # We do have younger matches.
720 # 1. Move index to point to the previous match.
721 # 2. Update display to indicate search found.
723 _history_substring_search_match_index+=-1
724 _history-substring-search-found
728 # We do not have younger matches.
730 # 1. Move the index beyond the beginning of
731 # _history_substring_search_matches.
732 # 2. Update display to indicate search not found.
734 _history_substring_search_match_index+=-1
735 _history-substring-search-not-found
739 # When HIST_FIND_NO_DUPS is set, meaning that only unique command lines from
740 # history should be matched, make sure the new and old results are different.
742 # However, if the HIST_IGNORE_ALL_DUPS shell option, or
743 # HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is set, then we already have a
744 # unique history, so in this case we do not need to do anything.
746 if [[ -o HIST_IGNORE_ALL_DUPS || -n $HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE ]]; then
750 if [[ -o HIST_FIND_NO_DUPS && $BUFFER == $_history_substring_search_result ]]; then
752 # Repeat the current search so that a different (unique) match is found.
754 _history-substring-search-down-search
758 # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
759 # vim: ft=zsh sw=2 ts=2 et