mirror of
https://github.com/zsh-users/zsh-history-substring-search.git
synced 2026-11-08 18:47:34 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0bdb0d47d | ||
|
|
349f731e32 | ||
|
|
14c8d2e0ff | ||
|
|
aa09f04747 | ||
|
|
87ce96b186 | ||
|
|
3235b885dd | ||
|
|
837d49959e | ||
|
|
8dd05bfcc1 | ||
|
|
8f5d8a5aa9 | ||
|
|
4f982d65b4 | ||
|
|
a7e6d94ba5 | ||
|
|
19b887667a | ||
|
|
2e28e23261 | ||
|
|
591ca3326a | ||
|
|
3bbc5a8cfa | ||
|
|
da5f0673b9 |
@@ -23,7 +23,15 @@ Install
|
||||
Using the [Homebrew]( https://brew.sh ) package manager:
|
||||
|
||||
brew install zsh-history-substring-search
|
||||
echo 'source /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
|
||||
echo 'source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
|
||||
|
||||
Using [Fig](https://fig.io):
|
||||
|
||||
Fig adds apps, shortcuts, and autocomplete to your existing terminal.
|
||||
|
||||
Install `zsh-history-substring-search` in just one click.
|
||||
|
||||
<a href="https://fig.io/plugins/other/zsh-history-substring-search" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
|
||||
|
||||
Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh):
|
||||
|
||||
@@ -35,22 +43,61 @@ Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh):
|
||||
|
||||
plugins=( [plugins...] zsh-history-substring-search)
|
||||
|
||||
3. Source `~/.zshrc` to take changes into account:
|
||||
3. Run `exec zsh` to take changes into account:
|
||||
|
||||
source ~/.zshrc
|
||||
exec zsh
|
||||
|
||||
Using [zplug](https://github.com/zplug/zplug):
|
||||
|
||||
1. Add this repo to `~/.zshrc`:
|
||||
|
||||
zplug "zsh-users/zsh-history-substring-search", as:plugin
|
||||
|
||||
Using [antigen](https://github.com/zsh-users/antigen):
|
||||
|
||||
1. Add the `antigen bundle` command just before `antigen apply`, like this:
|
||||
|
||||
```
|
||||
antigen bundle zsh-users/zsh-history-substring-search
|
||||
antigen apply
|
||||
```
|
||||
|
||||
2. Then, **after** `antigen apply`, add the key binding configurations, like this:
|
||||
|
||||
```
|
||||
# zsh-history-substring-search configuration
|
||||
bindkey '^[[A' history-substring-search-up # or '\eOA'
|
||||
bindkey '^[[B' history-substring-search-down # or '\eOB'
|
||||
HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=1
|
||||
```
|
||||
|
||||
Using [Zinit](https://github.com/zdharma-continuum/zinit):
|
||||
|
||||
1. Use the `Oh-my-zsh` Zinit snippet in `~/.zshrc`:
|
||||
|
||||
zinit snippet OMZ::plugins/git/git.plugin.zsh
|
||||
|
||||
2. Load the plugin in `~/.zshrc`:
|
||||
|
||||
zinit load 'zsh-users/zsh-history-substring-search'
|
||||
zinit ice wait atload'_history_substring_search_config'
|
||||
|
||||
3. Run `exec zsh` to take changes into account:
|
||||
|
||||
exec zsh
|
||||
|
||||
Usage
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
1. Load this script into your interactive ZSH session:
|
||||
|
||||
% source zsh-history-substring-search.zsh
|
||||
source zsh-history-substring-search.zsh
|
||||
|
||||
If you want to use [zsh-syntax-highlighting][6] along with this script,
|
||||
then make sure that you load it *before* you load this script:
|
||||
|
||||
% source zsh-syntax-highlighting.zsh
|
||||
% source zsh-history-substring-search.zsh
|
||||
source zsh-syntax-highlighting.zsh
|
||||
source zsh-history-substring-search.zsh
|
||||
|
||||
2. Bind keyboard shortcuts to this script's functions.
|
||||
|
||||
@@ -73,6 +120,10 @@ Usage
|
||||
bindkey "$terminfo[kcuu1]" history-substring-search-up
|
||||
bindkey "$terminfo[kcud1]" history-substring-search-down
|
||||
|
||||
Users have also observed that `[OA` and `[OB` are correct values,
|
||||
_even if_ these were not the observed values. If you are having trouble
|
||||
with the observed values, give these a try.
|
||||
|
||||
You might also want to bind the Control-P/N keys for use in EMACS mode:
|
||||
|
||||
bindkey -M emacs '^P' history-substring-search-up
|
||||
@@ -161,6 +212,9 @@ default values.
|
||||
receive globally unique search results only once, then use this
|
||||
configuration variable, or use `setopt HIST_IGNORE_ALL_DUPS`.
|
||||
|
||||
* `HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT` is a global variable that
|
||||
defines a timeout in seconds for clearing the search highlight.
|
||||
|
||||
|
||||
History
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
@@ -406,7 +406,24 @@ _history-substring-search-end() {
|
||||
|
||||
# For debugging purposes:
|
||||
# zle -R "mn: "$_history_substring_search_match_index" m#: "${#_history_substring_search_matches}
|
||||
# read -k -t 200 && zle -U $REPLY
|
||||
# read -k -t 200 && zle -U -- "$REPLY"
|
||||
|
||||
#
|
||||
# When this function returns, z-sy-h runs its line-pre-redraw hook. It has no
|
||||
# logic for determining highlight priority, when two different memo= marked
|
||||
# region highlights overlap; instead, it always prioritises itself. Below is
|
||||
# a workaround for dealing with it.
|
||||
#
|
||||
if [[ $_history_substring_search_zsh_5_9 -eq 1 ]]; then
|
||||
zle -R
|
||||
#
|
||||
# After line redraw with desired highlight, wait for timeout or user input
|
||||
# before removing search highlight and exiting. This ensures no highlights
|
||||
# are left lingering after search is finished.
|
||||
#
|
||||
read -k -t ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT:-1} && zle -U -- "$REPLY"
|
||||
region_highlight=( "${(@)region_highlight:#*${highlight_memo}*}" )
|
||||
fi
|
||||
|
||||
# Exit successfully from the history-substring-search-* widgets.
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user