7e398391dbd11a1974c8b35913d268853a8a21be
- Author
- Andrew Janke <andrew@apjanke.net>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/history-substring-search/README.markdown b/plugins/history-substring-search/README.markdown
2deleted file mode 100644
3index c154afdce90afe7fa7ca3272f412b86e7984c5fa..0000000000000000000000000000000000000000
4--- a/plugins/history-substring-search/README.markdown
5+++ /dev/null
6@@ -1,7 +0,0 @@
7-To activate this script, please include it the `plugins` variable within `~/.zshrc`
8-
9- `plugins=(git history-substring-search)`
10-
11-See the "history-substring-search.zsh" file for more information:
12-
13- `sed -n '2,/^$/s/^#//p' history-substring-search.zsh | more`
14diff --git a/plugins/history-substring-search/README.md b/plugins/history-substring-search/README.md
15new file mode 100644
16index 0000000000000000000000000000000000000000..0c02e91b1b2e2a17a200ded801ef74559d9e9023
17--- /dev/null
18+++ b/plugins/history-substring-search/README.md
19@@ -0,0 +1,149 @@
20+zsh-history-substring-search
21+==============================================================================
22+
23+This is a clean-room implementation of the [Fish shell][1]'s history search
24+feature, where you can type in any part of any previously entered command
25+and press the UP and DOWN arrow keys to cycle through the matching commands.
26+You can also use K and J in VI mode or ^P and ^N in EMACS mode for the same.
27+
28+[1]: http://fishshell.com
29+[2]: http://www.zsh.org/mla/users/2009/msg00818.html
30+[3]: http://sourceforge.net/projects/fizsh/
31+[4]: https://github.com/robbyrussell/oh-my-zsh/pull/215
32+[5]: https://github.com/zsh-users/zsh-history-substring-search
33+[6]: https://github.com/zsh-users/zsh-syntax-highlighting
34+
35+------------------------------------------------------------------------------
36+Requirements
37+------------------------------------------------------------------------------
38+
39+* [ZSH](http://zsh.sourceforge.net) 4.3 or newer
40+
41+------------------------------------------------------------------------------
42+Usage
43+------------------------------------------------------------------------------
44+
45+1. Load this script into your interactive ZSH session:
46+
47+ % source zsh-history-substring-search.zsh
48+
49+ If you want to use [zsh-syntax-highlighting][6] along with this script,
50+ then make sure that you load it *before* you load this script:
51+
52+ % source zsh-syntax-highlighting.zsh
53+ % source zsh-history-substring-search.zsh
54+
55+2. Bind keyboard shortcuts to this script's functions:
56+
57+ # bind UP and DOWN arrow keys
58+ zmodload zsh/terminfo
59+ bindkey "$terminfo[kcuu1]" history-substring-search-up
60+ bindkey "$terminfo[kcud1]" history-substring-search-down
61+
62+ # bind UP and DOWN arrow keys (compatibility fallback
63+ # for Ubuntu 12.04, Fedora 21, and MacOSX 10.9 users)
64+ bindkey '^[[A' history-substring-search-up
65+ bindkey '^[[B' history-substring-search-down
66+
67+ # bind P and N for EMACS mode
68+ bindkey -M emacs '^P' history-substring-search-up
69+ bindkey -M emacs '^N' history-substring-search-down
70+
71+ # bind k and j for VI mode
72+ bindkey -M vicmd 'k' history-substring-search-up
73+ bindkey -M vicmd 'j' history-substring-search-down
74+
75+3. Type any part of any previous command and then:
76+
77+ * Press the UP arrow key to select the nearest command that (1) contains
78+ your query and (2) is older than the current command in the command
79+ history.
80+
81+ * Press the DOWN arrow key to select the nearest command that (1)
82+ contains your query and (2) is newer than the current command in the
83+ command history.
84+
85+ * Press ^U (the Control and U keys simultaneously) to abort the search.
86+
87+4. If a matching command spans more than one line of text, press the LEFT
88+ arrow key to move the cursor away from the end of the command, and then:
89+
90+ * Press the UP arrow key to move the cursor to the line above. When the
91+ cursor reaches the first line of the command, pressing the UP arrow
92+ key again will cause this script to perform another search.
93+
94+ * Press the DOWN arrow key to move the cursor to the line below. When
95+ the cursor reaches the last line of the command, pressing the DOWN
96+ arrow key again will cause this script to perform another search.
97+
98+------------------------------------------------------------------------------
99+Configuration
100+------------------------------------------------------------------------------
101+
102+This script defines the following global variables. You may override their
103+default values only after having loaded this script into your ZSH session.
104+
105+* HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND is a global variable that defines
106+ how the query should be highlighted inside a matching command. Its default
107+ value causes this script to highlight using bold, white text on a magenta
108+ background. See the "Character Highlighting" section in the zshzle(1) man
109+ page to learn about the kinds of values you may assign to this variable.
110+
111+* HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND is a global variable that
112+ defines how the query should be highlighted when no commands in the
113+ history match it. Its default value causes this script to highlight using
114+ bold, white text on a red background. See the "Character Highlighting"
115+ section in the zshzle(1) man page to learn about the kinds of values you
116+ may assign to this variable.
117+
118+* HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS is a global variable that defines
119diff --git a/plugins/history-substring-search/history-substring-search.plugin.zsh b/plugins/history-substring-search/history-substring-search.plugin.zsh
120index 99a5922c5faa3d3130578e119e18a4d7ad6eac55..25fd3a2daf8d512aa8f0d369285e8ed676aa4a3e 100644
121--- a/plugins/history-substring-search/history-substring-search.plugin.zsh
122+++ b/plugins/history-substring-search/history-substring-search.plugin.zsh
123@@ -1,6 +1,6 @@
124-# This file integrates the history-substring-search script into oh-my-zsh.
125+# This file integrates the zsh-history-substring-search script into oh-my-zsh.
126
127-source "$ZSH/plugins/history-substring-search/history-substring-search.zsh"
128+source "${0:r:r}.zsh"
129
130 if test "$CASE_SENSITIVE" = true; then
131 unset HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS
132@@ -10,3 +10,14 @@ if test "$DISABLE_COLOR" = true; then
133 unset HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND
134 unset HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND
135 fi
136+
137+
138+# Bind terminal-specific up and down keys
139+
140+if [[ -n "$terminfo[kcuu1]" ]]; then
141+ bindkey "$terminfo[kcuu1]" history-substring-search-up
142+fi
143+if [[ -n "$terminfo[kcud1]" ]]; then
144+ bindkey "$terminfo[kcud1]" history-substring-search-down
145+fi
146+
147diff --git a/plugins/history-substring-search/history-substring-search.zsh b/plugins/history-substring-search/history-substring-search.zsh
148index 65f0750db5aca13767e20e12f1ead3e5a19c182e..ad316acc84b3a015d75d94500321a2d3d353e2ec 100644
149--- a/plugins/history-substring-search/history-substring-search.zsh
150+++ b/plugins/history-substring-search/history-substring-search.zsh
151@@ -1,95 +1,4 @@
152 #!/usr/bin/env zsh
153-#
154-# This is a clean-room implementation of the Fish[1] shell's history search
155-# feature, where you can type in any part of any previously entered command
156-# and press the UP and DOWN arrow keys to cycle through the matching commands.
157-#
158-#-----------------------------------------------------------------------------
159-# Usage
160-#-----------------------------------------------------------------------------
161-#
162-# 1. Load this script into your interactive ZSH session:
163-#
164-# % source history-substring-search.zsh
165-#
166-# If you want to use the zsh-syntax-highlighting[6] script along with this
167-# script, then make sure that you load it *before* you load this script:
168-#
169-# % source zsh-syntax-highlighting.zsh
170-# % source history-substring-search.zsh
171-#
172-# 2. Type any part of any previous command and then:
173-#
174-# * Press the UP arrow key to select the nearest command that (1) contains
175-# your query and (2) is older than the current command in the command
176-# history.
177-#
178-# * Press the DOWN arrow key to select the nearest command that (1)
179-# contains your query and (2) is newer than the current command in the
180-# command history.
181-#
182-# * Press ^U (the Control and U keys simultaneously) to abort the search.
183-#
184-# 3. If a matching command spans more than one line of text, press the LEFT
185-# arrow key to move the cursor away from the end of the command, and then:
186-#
187-# * Press the UP arrow key to move the cursor to the line above. When the
188-# cursor reaches the first line of the command, pressing the UP arrow
189-# key again will cause this script to perform another search.
190-#
191-# * Press the DOWN arrow key to move the cursor to the line below. When
192-# the cursor reaches the last line of the command, pressing the DOWN
193-# arrow key again will cause this script to perform another search.
194-#
195-#-----------------------------------------------------------------------------
196-# Configuration
197-#-----------------------------------------------------------------------------
198-#
199-# This script defines the following global variables. You may override their
200-# default values only after having loaded this script into your ZSH session.
201-#
202-# * HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND is a global variable that defines
203-# how the query should be highlighted inside a matching command. Its default
204-# value causes this script to highlight using bold, white text on a magenta
205-# background. See the "Character Highlighting" section in the zshzle(1) man
206-# page to learn about the kinds of values you may assign to this variable.
207-#
208-# * HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND is a global variable that
209-# defines how the query should be highlighted when no commands in the
210-# history match it. Its default value causes this script to highlight using
211-# bold, white text on a red background. See the "Character Highlighting"
212-# section in the zshzle(1) man page to learn about the kinds of values you
213-# may assign to this variable.
214-#
215-# * HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS is a global variable that defines
216-# how the command history will be searched for your query. Its default value
217-# causes this script to perform a case-insensitive search. See the "Globbing
218-# Flags" section in the zshexpn(1) man page to learn about the kinds of
219-# values you may assign to this variable.
220-#
221-#-----------------------------------------------------------------------------
222-# History
223-#-----------------------------------------------------------------------------
224-#
225-# This script was originally written by Peter Stephenson[2], who published it
226-# to the ZSH users mailing list (thereby making it public domain) in September
227-# 2009. It was later revised by Guido van Steen and released under the BSD
228-# license (see below) as part of the fizsh[3] project in January 2011.
229-#
230-# It was later extracted from fizsh[3] release 1.0.1, refactored heavily, and
231-# repackaged as both an oh-my-zsh plugin[4] and as an independently loadable
232-# ZSH script[5] by Suraj N. Kurapati in 2011.
233-#
234-# It was further developed[4] by Guido van Steen, Suraj N. Kurapati, Sorin
235-# Ionescu, and Vincent Guerci in 2011.
236-#
237-# [1]: http://fishshell.com
238-# [2]: http://www.zsh.org/mla/users/2009/msg00818.html
239-# [3]: http://sourceforge.net/projects/fizsh/
240-# [4]: https://github.com/robbyrussell/oh-my-zsh/pull/215
241-# [5]: https://github.com/sunaku/zsh-history-substring-search
242-# [6]: https://github.com/nicoulaj/zsh-syntax-highlighting
243-#
244 ##############################################################################
245 #
246 # Copyright (c) 2009 Peter Stephenson
247@@ -140,7 +49,7 @@ HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'
248 # the main ZLE widgets
249 #-----------------------------------------------------------------------------
250
251diff --git a/plugins/history-substring-search/update-from-upstream.zsh b/plugins/history-substring-search/update-from-upstream.zsh
252index 45950f447753dbba35caca866c8da328d91905ed..6e6cca5d5ac8a81a197def1db5699acc91717188 100755
253--- a/plugins/history-substring-search/update-from-upstream.zsh
254+++ b/plugins/history-substring-search/update-from-upstream.zsh
255@@ -24,20 +24,21 @@
256 set -e
257
258
259-UPSTREAM_BASE=zsh-history-substring-search
260-UPSTREAM_REPO=zsh-users/$UPSTREAM_BASE
261+upstream_basename=zsh-history-substring-search
262+plugin_basename=history-substring-search
263+UPSTREAM_REPO=zsh-users/$upstream_basename
264 need_repo_cleanup=false
265 upstream_github_url="https://github.com/$UPSTREAM_REPO"
266
267 if [[ -z "$UPSTREAM_REPO_PATH" ]]; then
268 # Do a clean checkout
269 my_tempdir=$(mktemp -d -t omz-update-histsubstrsrch)
270- UPSTREAM_REPO_PATH="$my_tempdir/$UPSTREAM_BASE"
271+ UPSTREAM_REPO_PATH="$my_tempdir/$upstream_basename"
272 git clone "$upstream_github_url" "$UPSTREAM_REPO_PATH"
273 need_repo_cleanup=true
274 print "Checked out upstream repo to $UPSTREAM_REPO_PATH"
275 else
276- print "Using existing zsh-history-substring-search repo at $UPSTREAM_REPO_PATH"
277+ print "Using existing $upstream_basename repo at $UPSTREAM_REPO_PATH"
278 fi
279
280 upstream="$UPSTREAM_REPO_PATH"
281@@ -45,14 +46,16 @@ upstream="$UPSTREAM_REPO_PATH"
282 # Figure out what we're pulling in
283 upstream_sha=$(cd $upstream && git rev-parse HEAD)
284 upstream_commit_date=$(cd $upstream && git log -1 --pretty=format:%ci)
285+upstream_just_date=${${=upstream_commit_date}[1]}
286 print "upstream SHA: $upstream_sha"
287-print "upstream commit date: $upstream_commit_date"
288+print "upstream commit time: $upstream_commit_date"
289+print "upstream commit date: $upstream_just_date"
290 print
291
292 # Copy the files over, using the OMZ plugin's names where needed
293 cp -v "$upstream"/* .
294-mv zsh-history-substring-search.plugin.zsh history-substring-search.plugin.zsh
295-mv zsh-history-substring-search.zsh history-substring-search.zsh
296+mv -v zsh-history-substring-search.zsh $plugin_basename.zsh
297+mv -v zsh-history-substring-search.plugin.zsh $plugin_basename.plugin.zsh
298
299 if [[ $need_repo_cleanup == true ]]; then
300 print "Removing temporary repo at $my_tempdir"
301@@ -63,19 +66,38 @@ fi
302
303 print
304 print "Updating files with OMZ-specific stuff"
305+print
306+
307+# OMZ binds the keys as part of the plugin loading
308+
309+cat >> $plugin_basename.plugin.zsh <<EOF
310+
311+
312+# Bind terminal-specific up and down keys
313+
314+if [[ -n "\$terminfo[kcuu1]" ]]; then
315+ bindkey "\$terminfo[kcuu1]" history-substring-search-up
316+fi
317+if [[ -n "\$terminfo[kcud1]" ]]; then
318+ bindkey "\$terminfo[kcud1]" history-substring-search-down
319+fi
320+
321+EOF
322
323 # Tack OMZ-specific notes on to readme
324+
325 thin_line="------------------------------------------------------------------------------"
326 cat >> README.md <<EOF
327
328 $thin_line
329-Oh My Zsh Notes
330+Oh My Zsh Distribution Notes
331 $thin_line
332
333-This is Oh My Zsh's repackaging of zsh-history-substring-search as an OMZ module
334-inside the Oh My Zsh distribution.
335+What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search
336+as an OMZ module inside the Oh My Zsh distribution.
337
338-The upstream repo, $UPSTREAM_REPO, can be found on GitHub at $upstream_github_url.
339+The upstream repo, $UPSTREAM_REPO, can be found on GitHub at
340+$upstream_github_url.
341
342 This downstream copy was last updated from the following upstream commit:
343
344@@ -84,11 +106,22 @@ This downstream copy was last updated from the following upstream commit:
345
346 Everything above this section is a copy of the original upstream's README, so things
347 may differ slightly when you're using this inside OMZ. In particular, you do not
348-need to set up key bindings yourself in \`~/.zshrc\`; the OMZ plugin does that for
349-you.
350+need to set up key bindings for the up and down arrows yourself in \`~/.zshrc\`; the OMZ
351+plugin does that for you. You may still want to set up additional emacs- or vi-specific
352+bindings as mentioned above.
353
354 EOF