d93401c642d1e5c87b06d7622bddb9bfd5eab383

Author
Tabrez Mohammed <me@tabrezmohammed.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(history-substring-search): update to upstream (#12164)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/history-substring-search/README.md b/plugins/history-substring-search/README.md
  2index 6d8b56425affe877d1c102186eb042895568fb3e..eee279dfde79643a9dc8562fd7cf464bcedcdd9e 100644
  3--- a/plugins/history-substring-search/README.md
  4+++ b/plugins/history-substring-search/README.md
  5@@ -23,7 +23,15 @@ Install
  6 Using the [Homebrew]( https://brew.sh ) package manager:
  7 
  8     brew install zsh-history-substring-search
  9-    echo 'source /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
 10+    echo 'source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
 11+
 12+Using [Fig](https://fig.io):
 13+
 14+Fig adds apps, shortcuts, and autocomplete to your existing terminal.
 15+
 16+Install `zsh-history-substring-search` in just one click.
 17+
 18+<a href="https://fig.io/plugins/other/zsh-history-substring-search" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
 19 
 20 Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh):
 21 
 22@@ -33,24 +41,63 @@ Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh):
 23 
 24 2. Activate the plugin in `~/.zshrc`:
 25 
 26-        plugins=( [plugins...] history-substring-search)
 27+        plugins=( [plugins...] zsh-history-substring-search)
 28+
 29+3. Run `exec zsh`  to take changes into account:
 30+
 31+        exec zsh
 32+
 33+Using [zplug](https://github.com/zplug/zplug):
 34+
 35+1. Add this repo to `~/.zshrc`:
 36+
 37+        zplug "zsh-users/zsh-history-substring-search", as: plugin
 38+
 39+Using [antigen](https://github.com/zsh-users/antigen):
 40 
 41-3. Source `~/.zshrc`  to take changes into account:
 42+1. Add the `antigen bundle` command just before `antigen apply`, like this:
 43 
 44-        source ~/.zshrc
 45+``` 
 46+antigen bundle zsh-users/zsh-history-substring-search
 47+antigen apply
 48+```
 49+ 
 50+2. Then, **after** `antigen apply`, add the key binding configurations, like this:
 51+ 
 52+```
 53+# zsh-history-substring-search configuration
 54+bindkey '^[[A' history-substring-search-up # or '\eOA'
 55+bindkey '^[[B' history-substring-search-down # or '\eOB'
 56+HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=1
 57+```
 58+
 59+Using [Zinit](https://github.com/zdharma-continuum/zinit):
 60+
 61+1. Use the `Oh-my-zsh` Zinit snippet in `~/.zshrc`:
 62+
 63+        zinit snippet OMZ::plugins/git/git.plugin.zsh`
 64+
 65+2. Load the plugin in `~/.zshrc`:
 66+
 67+        zinit load 'zsh-users/zsh-history-substring-search
 68+        zinit ice wait atload'_history_substring_search_config'
 69+
 70+3. Run `exec zsh` to take changes into account:
 71+
 72+        exec zsh
 73 
 74 Usage
 75 ------------------------------------------------------------------------------
 76 
 77 1.  Load this script into your interactive ZSH session:
 78 
 79-        % source zsh-history-substring-search.zsh
 80+        source zsh-history-substring-search.zsh
 81 
 82     If you want to use [zsh-syntax-highlighting][6] along with this script,
 83     then make sure that you load it *before* you load this script:
 84 
 85-        % source zsh-syntax-highlighting.zsh
 86-        % source zsh-history-substring-search.zsh
 87+        source zsh-syntax-highlighting.zsh
 88+        source zsh-history-substring-search.zsh
 89 
 90 2.  Bind keyboard shortcuts to this script's functions.
 91 
 92@@ -73,6 +120,10 @@ Usage
 93           bindkey "$terminfo[kcuu1]" history-substring-search-up
 94           bindkey "$terminfo[kcud1]" history-substring-search-down
 95 
 96+      Users have also observed that `[OA` and `[OB` are correct values, 
 97+      _even if_ these were not the observed values. If you are having trouble
 98+      with the observed values, give these a try.
 99+
100       You might also want to bind the Control-P/N keys for use in EMACS mode:
101 
102           bindkey -M emacs '^P' history-substring-search-up
103@@ -115,7 +166,7 @@ Configuration
104 ------------------------------------------------------------------------------
105diff --git a/plugins/history-substring-search/history-substring-search.plugin.zsh b/plugins/history-substring-search/history-substring-search.plugin.zsh
106index 63f0bdd4200375023003b66b8581bf4f241c0ee3..05bdbcd75f7f263f9c2b820c270e530d021b89cb 100644
107--- a/plugins/history-substring-search/history-substring-search.plugin.zsh
108+++ b/plugins/history-substring-search/history-substring-search.plugin.zsh
109@@ -1,9 +1,5 @@
110-# Handle $0 according to the standard:
111-# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
112-0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
113-0="${${(M)0:#/*}:-$PWD/$0}"
114-
115-source ${0:A:h}/history-substring-search.zsh
116+0=${(%):-%N}
117+source ${0:A:h}/zsh-history-substring-search.zsh
118 
119 
120 # Bind terminal-specific up and down keys
121diff --git a/plugins/history-substring-search/history-substring-search.zsh b/plugins/history-substring-search/history-substring-search.zsh
122index c326778d41d409c048ac83e437faa0318e3590f3..471cc9ad116e8183a846b75a30591d37f4b0bb58 100644
123--- a/plugins/history-substring-search/history-substring-search.zsh
124+++ b/plugins/history-substring-search/history-substring-search.zsh
125@@ -43,11 +43,12 @@
126 # declare global configuration variables
127 #-----------------------------------------------------------------------------
128 
129-typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold'
130-typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold'
131-typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'
132-typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''
133-typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY=''
134+: ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold'}
135+: ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold'}
136+: ${HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'}
137+: ${HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''}
138+: ${HISTORY_SUBSTRING_SEARCH_FUZZY=''}
139+: ${HISTORY_SUBSTRING_SEARCH_PREFIXED=''}
140 
141 #-----------------------------------------------------------------------------
142 # declare internal global variables
143@@ -64,6 +65,7 @@ typeset -g -i _history_substring_search_raw_match_index
144 typeset -g -a _history_substring_search_matches
145 typeset -g -i _history_substring_search_match_index
146 typeset -g -A _history_substring_search_unique_filter
147+typeset -g -i _history_substring_search_zsh_5_9
148 
149 #-----------------------------------------------------------------------------
150 # the main ZLE widgets
151@@ -97,6 +99,11 @@ zle -N history-substring-search-down
152 #-----------------------------------------------------------------------------
153 
154 zmodload -F zsh/parameter
155+autoload -Uz is-at-least
156+
157+if is-at-least 5.9 $ZSH_VERSION; then
158+  _history_substring_search_zsh_5_9=1
159+fi
160 
161 #
162 # We have to "override" some keys and widgets if the
163@@ -117,80 +124,125 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
164   }
165 
166   #
167-  # The following snippet was taken from the zsh-syntax-highlighting project:
168-  #
169-  # https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161
170-  #
171-  # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
172-  # All rights reserved.
173-  #
174-  # Redistribution and use in source and binary forms, with or without
175-  # modification, are permitted provided that the following conditions are
176-  # met:
177-  #
178-  #  * Redistributions of source code must retain the above copyright
179-  #    notice, this list of conditions and the following disclaimer.
180-  #
181-  #  * Redistributions in binary form must reproduce the above copyright
182-  #    notice, this list of conditions and the following disclaimer in the
183-  #    documentation and/or other materials provided with the distribution.
184-  #
185-  #  * Neither the name of the zsh-syntax-highlighting contributors nor the
186-  #    names of its contributors may be used to endorse or promote products
187-  #    derived from this software without specific prior written permission.
188-  #
189-  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
190-  # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
191-  # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
192-  # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
193-  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
194-  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195-  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
196-  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
197-  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
198-  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
199-  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
200-  #
201-  #--------------8<-------------------8<-------------------8<-----------------
202-  # Rebind all ZLE widgets to make them invoke _zsh_highlights.
203-  _zsh_highlight_bind_widgets()
204-  {
205-    # Load ZSH module zsh/zleparameter, needed to override user defined widgets.
206-    zmodload zsh/zleparameter 2>/dev/null || {
207-      echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
208-      return 1
209-    }
210-
211-    # Override ZLE widgets to make them invoke _zsh_highlight.
212-    local cur_widget
213-    for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do
214-      case $widgets[$cur_widget] in
215+  # Check if $1 denotes the name of a callable function, i.e. it is fully
216+  # defined or it is marked for autoloading and autoloading it at the first
217+  # call to it will succeed. In particular, if $1 has been marked for
218+  # autoloading but is not available in $fpath, then it will return 1 (false).
219+  #
220+  # This is based on the zsh-syntax-highlighting plugin.
221+  #
222+  _history-substring-search-function-callable() {
223+    if (( ${+functions[$1]} )) && ! [[ "$functions[$1]" == *"builtin autoload -X"* ]]; then
224+      return 0 # already fully loaded