a32564e0ae87686702570f3f942977bc9280f178
- Author
- Felipe Contreras <felipe.contreras@gmail.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git
2index 78a6dbb3d19adb2940d5ea67dc3ffb9c26ba0dbd..46d10d6f93a2873174485252d857f76d545c0100 100644
3--- a/plugins/gitfast/_git
4+++ b/plugins/gitfast/_git
5@@ -2,25 +2,24 @@
6
7 # zsh completion wrapper for git
8 #
9-# Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
10+# Copyright (c) 2012-2020 Felipe Contreras <felipe.contreras@gmail.com>
11 #
12-# You need git's bash completion script installed somewhere, by default it
13-# would be the location bash-completion uses.
14+# The recommended way to install this script is to make a copy of it as a
15+# file named '_git' inside any directory in your fpath.
16 #
17-# If your script is somewhere else, you can configure it on your ~/.zshrc:
18+# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
19+# and then add the following to your ~/.zshrc file:
20 #
21-# zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh
22+# fpath=(~/.zsh $fpath)
23 #
24-# The recommended way to install this script is to copy to '~/.zsh/_git', and
25-# then add the following to your ~/.zshrc file:
26+# You need git's bash completion script installed. By default bash-completion's
27+# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).
28+#
29+# If your bash completion script is somewhere else, you can specify the
30+# location in your ~/.zshrc:
31+#
32+# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
33 #
34-# fpath=(~/.zsh $fpath)
35-
36-complete ()
37-{
38- # do nothing
39- return 0
40-}
41
42 zstyle -T ':completion:*:*:git:*' tag-order && \
43 zstyle ':completion:*:*:git:*' tag-order 'common-commands'
44@@ -30,16 +29,17 @@ if [ -z "$script" ]; then
45 local -a locations
46 local e
47 locations=(
48- "$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash"
49- '/etc/bash_completion.d/git' # fedora, old debian
50- '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
51- '/usr/share/bash-completion/git' # gentoo
52+ "$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
53+ "$HOME/.local/share/bash-completion/completions/git"
54+ "$(pkg-config --variable=completionsdir bash-completion)"/git
55+ '/usr/share/bash-completion/completions/git'
56+ '/etc/bash_completion.d/git' # old debian
57 )
58 for e in $locations; do
59 test -f $e && script="$e" && break
60 done
61 fi
62-ZSH_VERSION='' . "$script"
63+GIT_SOURCING_ZSH_COMPLETION=y . "$script"
64
65 __gitcomp ()
66 {
67@@ -50,13 +50,35 @@ __gitcomp ()
68 case "$cur_" in
69 --*=)
70 ;;
71+ --no-*)
72+ local c IFS=$' \t\n'
73+ local -a array
74+ for c in ${=1}; do
75+ if [[ $c == "--" ]]; then
76+ continue
77+ fi
78+ c="$c${4-}"
79+ case $c in
80+ --*=|*.) ;;
81+ *) c="$c " ;;
82+ esac
83+ array+=("$c")
84+ done
85+ compset -P '*[=:]'
86+ compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
87+ ;;
88 *)
89 local c IFS=$' \t\n'
90 local -a array
91 for c in ${=1}; do
92+ if [[ $c == "--" ]]; then
93+ c="--no-...${4-}"
94+ array+=("$c ")
95+ break
96+ fi
97 c="$c${4-}"
98 case $c in
99- --*=*|*.) ;;
100+ --*=|*.) ;;
101 *) c="$c " ;;
102 esac
103 array+=("$c")
104@@ -71,35 +93,57 @@ __gitcomp_direct ()
105diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash
106index b6ff5dc0840e3667434b9d7f614007ae9bbfc77a..76ba7e79f0c500ab9a6a3bf60b220225ff79c34a 100644
107--- a/plugins/gitfast/git-completion.bash
108+++ b/plugins/gitfast/git-completion.bash
109@@ -29,13 +29,21 @@
110 # tell the completion to use commit completion. This also works with aliases
111 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
112 #
113+# Compatible with bash 3.2.57.
114+#
115 # You can set the following environment variables to influence the behavior of
116 # the completion routines:
117 #
118 # GIT_COMPLETION_CHECKOUT_NO_GUESS
119 #
120 # When set to "1", do not include "DWIM" suggestions in git-checkout
121-# completion (e.g., completing "foo" when "origin/foo" exists).
122+# and git-switch completion (e.g., completing "foo" when "origin/foo"
123+# exists).
124+#
125+# GIT_COMPLETION_SHOW_ALL
126+#
127+# When set to "1" suggest all options, including options which are
128+# typically hidden (e.g. '--allow-empty' for 'git commit').
129
130 case "$COMP_WORDBREAKS" in
131 *:*) : great ;;
132@@ -47,7 +55,7 @@ esac
133 # variable.
134 __git_find_repo_path ()
135 {
136- if [ -n "$__git_repo_path" ]; then
137+ if [ -n "${__git_repo_path-}" ]; then
138 # we already know where it is
139 return
140 fi
141@@ -92,6 +100,70 @@ __git ()
142 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
143 }
144
145+# Removes backslash escaping, single quotes and double quotes from a word,
146+# stores the result in the variable $dequoted_word.
147+# 1: The word to dequote.
148+__git_dequote ()
149+{
150+ local rest="$1" len ch
151+
152+ dequoted_word=""
153+
154+ while test -n "$rest"; do
155+ len=${#dequoted_word}
156+ dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
157+ rest="${rest:$((${#dequoted_word}-$len))}"
158+
159+ case "${rest:0:1}" in
160+ \\)
161+ ch="${rest:1:1}"
162+ case "$ch" in
163+ $'\n')
164+ ;;
165+ *)
166+ dequoted_word="$dequoted_word$ch"
167+ ;;
168+ esac
169+ rest="${rest:2}"
170+ ;;
171+ \')
172+ rest="${rest:1}"
173+ len=${#dequoted_word}
174+ dequoted_word="$dequoted_word${rest%%\'*}"
175+ rest="${rest:$((${#dequoted_word}-$len+1))}"
176+ ;;
177+ \")
178+ rest="${rest:1}"
179+ while test -n "$rest" ; do
180+ len=${#dequoted_word}
181+ dequoted_word="$dequoted_word${rest%%[\\\"]*}"
182+ rest="${rest:$((${#dequoted_word}-$len))}"
183+ case "${rest:0:1}" in
184+ \\)
185+ ch="${rest:1:1}"
186+ case "$ch" in
187+ \"|\\|\$|\`)
188+ dequoted_word="$dequoted_word$ch"
189+ ;;
190+ $'\n')
191+ ;;
192+ *)
193+ dequoted_word="$dequoted_word\\$ch"
194+ ;;
195+ esac
196+ rest="${rest:2}"
197+ ;;
198+ \")
199+ rest="${rest:1}"
200+ break
201+ ;;
202+ esac
203+ done
204+ ;;
205+ esac
206+ done
207+}
208+
209diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
210index fd2b049dbde3cd6b1a2583e7c32f3ea2915052be..54e123d632cd5cbc57215d9db7fae7b0981a01cf 100644
211--- a/plugins/gitfast/git-prompt.sh
212+++ b/plugins/gitfast/git-prompt.sh
213@@ -70,6 +70,15 @@
214 # state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
215 # is SP.
216 #
217+# When there is an in-progress operation such as a merge, rebase,
218+# revert, cherry-pick, or bisect, the prompt will include information
219+# related to the operation, often in the form "|<OPERATION-NAME>".
220+#
221+# When the repository has a sparse-checkout, a notification of the form
222+# "|SPARSE" will be included in the prompt. This can be shortened to a
223+# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
224+# by setting GIT_PS1_OMITSPARSESTATE.
225+#
226 # By default, __git_ps1 will compare HEAD to your SVN upstream if it can
227 # find one, or @{upstream} otherwise. Once you have set
228 # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
229@@ -88,7 +97,8 @@
230 # If you would like a colored hint about the current dirty state, set
231 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
232 # the colored output of "git status -sb" and are available only when
233-# using __git_ps1 for PROMPT_COMMAND or precmd.
234+# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
235+# but always available in Zsh.
236 #
237 # If you would like __git_ps1 to do nothing in the case when the current
238 # directory is set up to be ignored by git, then set
239@@ -286,6 +296,37 @@ __git_eread ()
240 test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
241 }
242
243+# see if a cherry-pick or revert is in progress, if the user has committed a
244+# conflict resolution with 'git commit' in the middle of a sequence of picks or
245+# reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read
246+# the todo file.
247+__git_sequencer_status ()
248+{
249+ local todo
250+ if test -f "$g/CHERRY_PICK_HEAD"
251+ then
252+ r="|CHERRY-PICKING"
253+ return 0;
254+ elif test -f "$g/REVERT_HEAD"
255+ then
256+ r="|REVERTING"
257+ return 0;
258+ elif __git_eread "$g/sequencer/todo" todo
259+ then
260+ case "$todo" in
261+ p[\ \ ]|pick[\ \ ]*)
262+ r="|CHERRY-PICKING"
263+ return 0
264+ ;;
265+ revert[\ \ ]*)
266+ r="|REVERTING"
267+ return 0
268+ ;;
269+ esac
270+ fi
271+ return 1
272+}
273+
274 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
275 # when called from PS1 using command substitution
276 # in this mode it prints text to add to bash PS1 prompt (includes branch name)
277@@ -390,6 +431,13 @@ __git_ps1 ()
278 return $exit
279 fi
280
281+ local sparse=""
282+ if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
283+ [ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
284+ [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
285+ sparse="|SPARSE"
286+ fi
287+
288 local r=""
289 local b=""
290 local step=""
291@@ -398,11 +446,7 @@ __git_ps1 ()
292 __git_eread "$g/rebase-merge/head-name" b
293 __git_eread "$g/rebase-merge/msgnum" step
294 __git_eread "$g/rebase-merge/end" total
295- if [ -f "$g/rebase-merge/interactive" ]; then
296- r="|REBASE-i"
297- else
298- r="|REBASE-m"
299- fi
300+ r="|REBASE"
301 else
302 if [ -d "$g/rebase-apply" ]; then
303 __git_eread "$g/rebase-apply/next" step
304@@ -417,10 +461,8 @@ __git_ps1 ()
305 fi
306 elif [ -f "$g/MERGE_HEAD" ]; then
307 r="|MERGING"
308- elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
309- r="|CHERRY-PICKING"
310- elif [ -f "$g/REVERT_HEAD" ]; then
311- r="|REVERTING"
312+ elif __git_sequencer_status; then
313diff --git a/plugins/gitfast/update b/plugins/gitfast/update
314index 05054245f1759b41a2ce31f822e6cb20c6f17d65..d0947e7d82be1d79cc527774779f900334d8947c 100755
315--- a/plugins/gitfast/update
316+++ b/plugins/gitfast/update
317@@ -1,9 +1,8 @@
318 #!/bin/sh
319
320-url="https://git.kernel.org/pub/scm/git/git.git/plain/contrib/completion"
321-version="2.16.0"
322+url="https://raw.githubusercontent.com/felipec/git-completion"
323+version="1.0"
324
325-curl -s -o _git "${url}/git-completion.zsh?h=v${version}" &&
326-curl -s -o git-completion.bash "${url}/git-completion.bash?h=v${version}" &&
327-curl -s -o git-prompt.sh "${url}/git-prompt.sh?h=v${version}" &&
328-git apply updates.patch
329+curl -s -o _git "${url}/v${version}/git-completion.zsh" &&
330+curl -s -o git-completion.bash "${url}/v${version}/git-completion.bash" &&
331+curl -s -o git-prompt.sh "${url}/v${version}/git-prompt.sh"
332diff --git a/plugins/gitfast/updates.patch b/plugins/gitfast/updates.patch
333deleted file mode 100644
334index 28a31f859c267c496ca0e455554d14e0d39b47a6..0000000000000000000000000000000000000000
335--- a/plugins/gitfast/updates.patch
336+++ /dev/null
337@@ -1,56 +0,0 @@
338-diff --git b/plugins/gitfast/_git a/plugins/gitfast/_git
339-index e2554130..a2e3bef5 100644
340---- b/plugins/gitfast/_git
341-+++ a/plugins/gitfast/_git
342-@@ -30,7 +30,7 @@ if [ -z "$script" ]; then
343- local -a locations
344- local e
345- locations=(
346-- $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
347-+ "$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash"
348- '/etc/bash_completion.d/git' # fedora, old debian
349- '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
350- '/usr/share/bash-completion/git' # gentoo
351-@@ -214,8 +214,10 @@ _git ()
352-
353- if (( $+functions[__${service}_zsh_main] )); then
354- __${service}_zsh_main
355-- else
356-+ elif (( $+functions[__${service}_main] )); then
357- emulate ksh -c __${service}_main
358-+ elif (( $+functions[_${service}] )); then
359-+ emulate ksh -c _${service}
360- fi
361-
362- let _ret && _default && _ret=0
363-diff --git b/plugins/gitfast/git-completion.bash a/plugins/gitfast/git-completion.bash
364-index 9c8f7380..14012cab 100644
365---- b/plugins/gitfast/git-completion.bash
366-+++ a/plugins/gitfast/git-completion.bash
367-@@ -2915,6 +2915,6 @@ __git_complete gitk __gitk_main
368- # when the user has tab-completed the executable name and consequently
369- # included the '.exe' suffix.
370- #
371--if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
372-+if [[ "$OSTYPE" = cygwin* ]]; then
373- __git_complete git.exe __git_main
374- fi
375-diff --git b/plugins/gitfast/git-prompt.sh a/plugins/gitfast/git-prompt.sh
376-index 97eacd78..c1de34eb 100644
377---- b/plugins/gitfast/git-prompt.sh
378-+++ a/plugins/gitfast/git-prompt.sh
379-@@ -502,9 +502,11 @@ __git_ps1 ()
380-
381- local z="${GIT_PS1_STATESEPARATOR-" "}"
382-
383-- # NO color option unless in PROMPT_COMMAND mode
384-- if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
385-- __git_ps1_colorize_gitstring
386-+ # NO color option unless in PROMPT_COMMAND mode or it's Zsh
387-+ if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
388-+ if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
389-+ __git_ps1_colorize_gitstring
390-+ fi
391- fi
392-
393- b=${b##refs/heads/}