Search highlight is cleared after a timeout, which is one second by default.
Timeout period can be changed by setting an environment variable; example below
for setting one minute timeout.
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT=60
Fixes#131
See 810c2dcede
I'm not sure if it should be used even in our dummy _zsh_highlight or
not and, to be honest, I couldn't figure out why is this dummy
_zsh_highlight needed at all, so I left it unchanged.
zsh-syntax-highlighting started using zle-line-pre-redraw hook instead
of the legacy "bind all widgets" if 1) zsh has the memo= feature (added
in version 5.9) and 2) add-zle-hook-widget is available.
Now when zsh-history-substring-search is loaded before
zsh-syntax-highlighting, it causes error:
_zsh_highlight_widget_zle-line-pre-redraw: job table full or recursion limit exceeded
See https://github.com/zsh-users/zsh-syntax-highlighting/pull/749
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.
otherwise users are obliged to set the config values *after* sourcing
the plugin. They're not able to do it before. Also, re-sourcing the
plugin will reset the values to the defaults again.
A similar change was done in zsh-autosuggestions in the past:
https://github.com/zsh-users/zsh-autosuggestions/commit/9e4d3c3
* `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`.
Co-authored-by: Xue Qianming <qianmingxue@microsoft.com>
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
With HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE, it can take a while to compute
all unique search results, which would normally keep the shell unresponsive
during this computation.
This commit separates the retrieval of all history matches from the
computation of the matches that need to be presented to the user (unique
matches only if HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is set). The
computation of the matches needing to be displayed is then done lazily,
and only when the user requests a new previously undisplayed result.
This keeps the response time fast while still enabling us to filter for
unique search results.
If HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is set to a non-empty string,
then all displayed search results will be unique even if the shell
option HIST_IGNORE_ALL_DUPS is not set.
We used to do a history search when the query string was empty, which
resulted in all history indices being returned, but they are never
actually used as _history-substring-search-up-history and
_history-substring-search-down-history will just act like ZSH up-history
and down-history if the query is empty. Removing this unnecessary lookup
should speed up the empty query case, especially if you have a long
history.
This is a pure refactoring patch and does note change any functionality.
We remove an unnecessary reversal of the history match array by swapping
the enumeration order of match indices. Older entries now have higher
internal indices than younger entries, and hence we start from 1.
Also removed one unreachable elif clause each from search-up and
search-down.
This is the best way I've found to remove duplicate entries while
keeping the most recent occurence, but I'm not a ZSH expert. There may
be a more efficient way.
There's no need to do a full numerical sort here, since we know the
keys will be in reverse numerical order, because (R) searches in last-
to-first order. Not a big deal, but this is just simpler and
presumably more efficient.
Also cleaned up a rather confusing comment about (on) being used to
remove duplicates, which it definitely doesn't.
This brings in the several improvements since the code was initially
added for compatibility. In particular, this fixes widget conflicts with
existing functions and executables by prefixing all redefined widgets
with "_zsh_highlight_widget_".