96108e1130964dd49e3467e117ee409f8e467455
- Author
- Marc Cornellà <marc.cornella@live.com>
- 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
252new file mode 100755
253index 0000000000000000000000000000000000000000..6e6cca5d5ac8a81a197def1db5699acc91717188
254--- /dev/null
255+++ b/plugins/history-substring-search/update-from-upstream.zsh
256@@ -0,0 +1,127 @@
257+#!/usr/bin/env zsh
258+#
259+# update-from-upstream.zsh
260+#
261+# This script updates the Oh My Zsh version of the zsh-history-substring-search
262+# plugin from the independent upstream repo. This is to be run by OMZ developers
263+# when they want to pull in new changes from upstream to OMZ. It is not run
264+# during normal use of the plugin.
265+#
266+# The official upstream repo is zsh-users/zsh-history-substring-search
267+# https://github.com/zsh-users/zsh-history-substring-search
268+#
269+# This is a zsh script, not a function. Call it with `zsh update-from-upstream.zsh`
270+# from the command line, running it from within the plugin directory.
271+#
272+# You can set the environment variable REPO_PATH to point it at an upstream
273+# repo you have already prepared. Otherwise, it will do a clean checkout of
274+# upstream's HEAD to a temporary local repo and use that.
275+
276+
277+# Just bail on any error so we don't have to do extra checking.
278+# This is a developer-use script, so terse output like that should
279+# be fine.
280+set -e
281+
282+
283+upstream_basename=zsh-history-substring-search
284+plugin_basename=history-substring-search
285+UPSTREAM_REPO=zsh-users/$upstream_basename
286+need_repo_cleanup=false
287+upstream_github_url="https://github.com/$UPSTREAM_REPO"
288+
289+if [[ -z "$UPSTREAM_REPO_PATH" ]]; then
290+ # Do a clean checkout
291+ my_tempdir=$(mktemp -d -t omz-update-histsubstrsrch)
292+ UPSTREAM_REPO_PATH="$my_tempdir/$upstream_basename"
293+ git clone "$upstream_github_url" "$UPSTREAM_REPO_PATH"
294+ need_repo_cleanup=true
295+ print "Checked out upstream repo to $UPSTREAM_REPO_PATH"
296+else
297+ print "Using existing $upstream_basename repo at $UPSTREAM_REPO_PATH"
298+fi
299+
300+upstream="$UPSTREAM_REPO_PATH"
301+
302+# Figure out what we're pulling in
303+upstream_sha=$(cd $upstream && git rev-parse HEAD)
304+upstream_commit_date=$(cd $upstream && git log -1 --pretty=format:%ci)
305+upstream_just_date=${${=upstream_commit_date}[1]}
306+print "upstream SHA: $upstream_sha"
307+print "upstream commit time: $upstream_commit_date"
308+print "upstream commit date: $upstream_just_date"
309+print
310+
311+# Copy the files over, using the OMZ plugin's names where needed
312+cp -v "$upstream"/* .
313+mv -v zsh-history-substring-search.zsh $plugin_basename.zsh
314+mv -v zsh-history-substring-search.plugin.zsh $plugin_basename.plugin.zsh
315+
316+if [[ $need_repo_cleanup == true ]]; then
317+ print "Removing temporary repo at $my_tempdir"
318+ rm -rf "$my_tempdir"
319+fi
320+
321+# Do OMZ-specific edits
322+
323+print
324+print "Updating files with OMZ-specific stuff"
325+print
326+
327+# OMZ binds the keys as part of the plugin loading
328+
329+cat >> $plugin_basename.plugin.zsh <<EOF
330+
331+
332+# Bind terminal-specific up and down keys
333+
334+if [[ -n "\$terminfo[kcuu1]" ]]; then
335+ bindkey "\$terminfo[kcuu1]" history-substring-search-up
336+fi
337+if [[ -n "\$terminfo[kcud1]" ]]; then
338+ bindkey "\$terminfo[kcud1]" history-substring-search-down
339+fi
340+
341+EOF
342+
343+# Tack OMZ-specific notes on to readme
344+
345+thin_line="------------------------------------------------------------------------------"
346+cat >> README.md <<EOF
347+
348+$thin_line
349+Oh My Zsh Distribution Notes
350+$thin_line
351+
352+What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search
353+as an OMZ module inside the Oh My Zsh distribution.
354+
355+The upstream repo, $UPSTREAM_REPO, can be found on GitHub at