3fd63fdf01344bb5f5f13a9c33eb0b7a72fe4771
- Author
- Andrew Stone <61954919+adrwstone@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/zsh-interactive-cd/LICENSE b/plugins/zsh-interactive-cd/LICENSE
2new file mode 100644
3index 0000000000000000000000000000000000000000..40b3f8d7aa7997e75c356bb1ddd9f6b46c20587b
4--- /dev/null
5+++ b/plugins/zsh-interactive-cd/LICENSE
6@@ -0,0 +1,375 @@
7+Copyright 2017-2018 Henry Chang
8+
9+Mozilla Public License Version 2.0
10+==================================
11+
12+1. Definitions
13+--------------
14+
15+1.1. "Contributor"
16+ means each individual or legal entity that creates, contributes to
17+ the creation of, or owns Covered Software.
18+
19+1.2. "Contributor Version"
20+ means the combination of the Contributions of others (if any) used
21+ by a Contributor and that particular Contributor's Contribution.
22+
23+1.3. "Contribution"
24+ means Covered Software of a particular Contributor.
25+
26+1.4. "Covered Software"
27+ means Source Code Form to which the initial Contributor has attached
28+ the notice in Exhibit A, the Executable Form of such Source Code
29+ Form, and Modifications of such Source Code Form, in each case
30+ including portions thereof.
31+
32+1.5. "Incompatible With Secondary Licenses"
33+ means
34+
35+ (a) that the initial Contributor has attached the notice described
36+ in Exhibit B to the Covered Software; or
37+
38+ (b) that the Covered Software was made available under the terms of
39+ version 1.1 or earlier of the License, but not also under the
40+ terms of a Secondary License.
41+
42+1.6. "Executable Form"
43+ means any form of the work other than Source Code Form.
44+
45+1.7. "Larger Work"
46+ means a work that combines Covered Software with other material, in
47+ a separate file or files, that is not Covered Software.
48+
49+1.8. "License"
50+ means this document.
51+
52+1.9. "Licensable"
53+ means having the right to grant, to the maximum extent possible,
54+ whether at the time of the initial grant or subsequently, any and
55+ all of the rights conveyed by this License.
56+
57+1.10. "Modifications"
58+ means any of the following:
59+
60+ (a) any file in Source Code Form that results from an addition to,
61+ deletion from, or modification of the contents of Covered
62+ Software; or
63+
64+ (b) any new file in Source Code Form that contains any Covered
65+ Software.
66+
67+1.11. "Patent Claims" of a Contributor
68+ means any patent claim(s), including without limitation, method,
69+ process, and apparatus claims, in any patent Licensable by such
70+ Contributor that would be infringed, but for the grant of the
71+ License, by the making, using, selling, offering for sale, having
72+ made, import, or transfer of either its Contributions or its
73+ Contributor Version.
74+
75+1.12. "Secondary License"
76+ means either the GNU General Public License, Version 2.0, the GNU
77+ Lesser General Public License, Version 2.1, the GNU Affero General
78+ Public License, Version 3.0, or any later versions of those
79+ licenses.
80+
81+1.13. "Source Code Form"
82+ means the form of the work preferred for making modifications.
83+
84+1.14. "You" (or "Your")
85+ means an individual or a legal entity exercising rights under this
86+ License. For legal entities, "You" includes any entity that
87+ controls, is controlled by, or is under common control with You. For
88+ purposes of this definition, "control" means (a) the power, direct
89+ or indirect, to cause the direction or management of such entity,
90+ whether by contract or otherwise, or (b) ownership of more than
91+ fifty percent (50%) of the outstanding shares or beneficial
92+ ownership of such entity.
93+
94+2. License Grants and Conditions
95+--------------------------------
96+
97+2.1. Grants
98+
99+Each Contributor hereby grants You a world-wide, royalty-free,
100+non-exclusive license:
101+
102+(a) under intellectual property rights (other than patent or trademark)
103+ Licensable by such Contributor to use, reproduce, make available,
104+ modify, display, perform, distribute, and otherwise exploit its
105+ Contributions, either on an unmodified basis, with Modifications, or
106diff --git a/plugins/zsh-interactive-cd/README.md b/plugins/zsh-interactive-cd/README.md
107index c8337fbc893ed385f15634c5500d64e78b939ed5..4bffbf04af7eb312da6d74adffb78aedc08fbf74 100644
108--- a/plugins/zsh-interactive-cd/README.md
109+++ b/plugins/zsh-interactive-cd/README.md
110@@ -1,23 +1,15 @@
111 # zsh-interactive-cd
112
113-This plugin adds a fish-like interactive tab completion for the `cd` command.
114+## Demo
115
116-To use it, add `zsh-interactive-cd` to the plugins array of your zshrc file:
117-```zsh
118-plugins=(... zsh-interactive-cd)
119-```
120+
121
122-
123+## Installation
124
125-## Usage
126-
127-Press tab for completion as usual, it'll launch fzf automatically. Check fzf’s [readme](https://github.com/junegunn/fzf#search-syntax) for more search syntax usage.
128+1. Install [fzf](https://github.com/junegunn/fzf) by following its [installation instruction](https://github.com/junegunn/fzf#installation).
129
130-## Requirements
131+2. Source `zsh-interactive-cd.plugin.zsh` in `.zshrc`.
132
133-This plugin requires [fzf](https://github.com/junegunn/fzf). Install it by following
134-its [installation instructions](https://github.com/junegunn/fzf#installation).
135-
136-## Author
137+## Usage
138
139-[Henry Chang](https://github.com/changyuheng)
140+Press tab for completion as usual, it'll launch fzf automatically. Check fzf’s [readme](https://github.com/junegunn/fzf#search-syntax) for more search syntax usage.
141diff --git a/plugins/zsh-interactive-cd/demo.gif b/plugins/zsh-interactive-cd/demo.gif
142new file mode 100644
143index 0000000000000000000000000000000000000000..3568ecf954a3c2049908e97d355f6f187236be2e
144Binary files /dev/null and b/plugins/zsh-interactive-cd/demo.gif differ
145diff --git a/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh b/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh
146index b0520c23936b25db6ec40cf18b1a41f23792c96b..0ae9d50a736e65c221534faa7364a9b689fe319e 100644
147--- a/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh
148+++ b/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh
149@@ -1,4 +1,10 @@
150-# Copyright (c) 2017 Henry Chang
151+#!/usr/bin/env zsh
152+#
153+# Copyright 2017-2018 Henry Chang
154+#
155+# This Source Code Form is subject to the terms of the Mozilla Public
156+# License, v. 2.0. If a copy of the MPL was not distributed with this
157+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
158
159 __zic_fzf_prog() {
160 [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] \
161@@ -17,7 +23,7 @@ __zic_matched_subdir_list() {
162 length=0
163 fi
164 find -L "$dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null \
165- | cut -b $(( ${length} + 2 ))- | sed '/^$/d' | while read -r line; do
166+ | cut -b $(( ${length} + 2 ))- | command sed '/^$/d' | while read -r line; do
167 if [[ "${line[1]}" == "." ]]; then
168 continue
169 fi
170@@ -32,13 +38,19 @@ __zic_matched_subdir_list() {
171 seg=$(basename -- "$1")
172 starts_with_dir=$( \
173 find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
174- 2>/dev/null | cut -b $(( ${length} + 2 ))- | sed '/^$/d' \
175+ 2>/dev/null | cut -b $(( ${length} + 2 ))- | command sed '/^$/d' \
176 | while read -r line; do
177 if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
178 continue
179 fi
180- if [[ "$line" == "$seg"* ]]; then
181- echo "$line"
182+ if [ "$zic_case_insensitive" = "true" ]; then
183+ if [[ "$line:u" == "$seg:u"* ]]; then
184+ echo "$line"
185+ fi
186+ else
187+ if [[ "$line" == "$seg"* ]]; then
188+ echo "$line"
189+ fi
190 fi
191 done
192 )
193@@ -46,19 +58,36 @@ __zic_matched_subdir_list() {
194 echo "$starts_with_dir"
195 else
196 find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
197- 2>/dev/null | cut -b $(( ${length} + 2 ))- | sed '/^$/d' \
198+ 2>/dev/null | cut -b $(( ${length} + 2 ))- | command sed '/^$/d' \
199 | while read -r line; do
200 if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
201 continue
202 fi
203- if [[ "$line" == *"$seg"* ]]; then
204- echo "$line"
205+ if [ "$zic_case_insensitive" = "true" ]; then
206+ if [[ "$line:u" == *"$seg:u"* ]]; then
207+ echo "$line"
208+ fi
209+ else
210+ if [[ "$line" == *"$seg"* ]]; then
211+ echo "$line"
212+ fi
213 fi
214 done
215 fi
216 fi
217 }
218
219+__zic_fzf_bindings() {
220+ autoload is-at-least
221+ fzf=$(__zic_fzf_prog)
222+
223+ if $(is-at-least '0.21.0' $(${=fzf} --version)); then
224+ echo 'shift-tab:up,tab:down,bspace:backward-delete-char/eof'
225+ else
226+ echo 'shift-tab:up,tab:down'
227+ fi
228+}
229+
230 _zic_list_generator() {
231 __zic_matched_subdir_list "${(Q)@[-1]}" | sort
232 }
233@@ -75,6 +104,7 @@ _zic_complete() {
234 fi
235
236 fzf=$(__zic_fzf_prog)
237+ fzf_bindings=$(__zic_fzf_bindings)
238
239 if [ $(echo $l | wc -l) -eq 1 ]; then
240 matches=${(q)l}
241@@ -82,7 +112,7 @@ _zic_complete() {
242 matches=$(echo $l \
243 | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} \
244 --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS \
245- --bind 'shift-tab:up,tab:down'" ${=fzf} \
246+ --bind '${fzf_bindings}'" ${=fzf} \
247 | while read -r item; do
248 echo -n "${(q)item} "