6f9650d940f31d9d10f07a176a85ca3b814f448f
- 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 988f5b1c6ea794ba4dac0d180e5dee8f8ebbdcfc..31bf88c1c53a2a6f251b96125237ba854ede69e9 100644
3--- a/plugins/gitfast/_git
4+++ b/plugins/gitfast/_git
5@@ -33,8 +33,9 @@ if [ -z "$script" ]; then
6 bash_completion='/usr/share/bash-completion/completions/'
7
8 locations=(
9- "$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
10+ "${${funcsourcetrace[1]%:*}:A:h}"/git-completion.bash
11 "$HOME/.local/share/bash-completion/completions/git"
12+ '/usr/local/share/bash-completion/completions/git'
13 "$bash_completion/git"
14 '/etc/bash_completion.d/git' # old debian
15 )
16@@ -51,13 +52,20 @@ functions[complete]="$old_complete"
17
18 __gitcompadd ()
19 {
20- compadd -Q -p "${2-}" -S "${3- }" ${@[4,-1]} -- ${=1} && _ret=0
21+ compadd -p "${2-}" -S "${3- }" -q -- ${=1} && _ret=0
22 }
23
24 __gitcomp ()
25 {
26 emulate -L zsh
27
28+ IFS=$' \t\n' __gitcompadd "$1" "${2-}" "${4- }"
29+}
30+
31+__gitcomp_opts ()
32+{
33+ emulate -L zsh
34+
35 local cur_="${3-$cur}"
36
37 [[ "$cur_" == *= ]] && return
38@@ -70,7 +78,7 @@ __gitcomp ()
39 break
40 fi
41
42- if [[ -z "${4-}" ]]; then
43+ if [[ -z "${4+set}" ]]; then
44 case $c in
45 *=) c="${c%=}"; sfx="=" ;;
46 *.) sfx="" ;;
47@@ -79,7 +87,7 @@ __gitcomp ()
48 else
49 sfx="$4"
50 fi
51- __gitcompadd "$c" "${2-}" "$sfx" -q
52+ __gitcompadd "$c" "${2-}" "$sfx"
53 done
54 }
55
56@@ -87,7 +95,10 @@ __gitcomp_nl ()
57 {
58 emulate -L zsh
59
60- IFS=$'\n' __gitcompadd "$1" "${2-}" "${4- }"
61+ # words that don't end up in space
62+ compadd -p "${2-}" -S "${4- }" -q -- ${${(f)1}:#*\ } && _ret=0
63+ # words that end in space
64+ compadd -p "${2-}" -S " ${4- }" -q -- ${${(M)${(f)1}:#*\ }% } && _ret=0
65 }
66
67 __gitcomp_file ()
68@@ -107,21 +118,6 @@ __gitcomp_file_direct ()
69 __gitcomp_file "$1" ""
70 }
71
72-__gitcomp_nl_append ()
73-{
74- __gitcomp_nl "$@"
75-}
76-
77-__gitcomp_direct_append ()
78-{
79- __gitcomp_direct "$@"
80-}
81-
82-_git_zsh ()
83-{
84- __gitcomp "v1.2"
85-}
86-
87 __git_complete_command ()
88 {
89 emulate -L zsh
90@@ -206,9 +202,7 @@ __git_zsh_main ()
91 {
92 local curcontext="$curcontext" state state_descr line
93 typeset -A opt_args
94- local -a orig_words __git_C_args
95-
96- orig_words=( ${words[@]} )
97+ local -a __git_C_args
98
99 _arguments -C \
100 '(-p --paginate -P --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
101@@ -245,7 +239,7 @@ __git_zsh_main ()
102 emulate ksh -c __git_complete_config_variable_name_and_value
103 ;;
104 (arg)
105diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash
106index f7b09b2c1ce408190d97011ebfbd5d330154b573..2603ba7bb4b9fb8081a2b68aa19089279f21b637 100644
107--- a/plugins/gitfast/git-completion.bash
108+++ b/plugins/gitfast/git-completion.bash
109@@ -29,6 +29,15 @@
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+# If you have a command that is not part of git, but you would still
114+# like completion, you can use __git_complete:
115+#
116+# __git_complete gl git_log
117+#
118+# Or if it's a main command (i.e. git or gitk):
119+#
120+# __git_complete gk gitk
121+#
122 # Compatible with bash 3.2.57.
123 #
124 # You can set the following environment variables to influence the behavior of
125@@ -45,6 +54,145 @@
126 # When set to "1" suggest all options, including options which are
127 # typically hidden (e.g. '--allow-empty' for 'git commit').
128
129+# The following functions are meant to modify COMPREPLY, which should not be
130+# modified directly. The purpose is to localize the modifications so it's
131+# easier to emulate it in Zsh. Every time a new __gitcomp* function is added,
132+# the corresponding function should be added to Zsh.
133+
134+__gitcompadd ()
135+{
136+ local x i=${#COMPREPLY[@]}
137+ for x in $1; do
138+ if [[ "$x" == "$3"* ]]; then
139+ COMPREPLY[i++]="$2$x$4"
140+ fi
141+ done
142+}
143+
144+# Creates completion replies.
145+# It accepts 1 to 4 arguments:
146+# 1: List of possible completion words.
147+# 2: A prefix to be added to each possible completion word (optional).
148+# 3: Generate possible completion matches for this word (optional).
149+# 4: A suffix to be appended to each possible completion word (optional).
150+__gitcomp ()
151+{
152+ local IFS=$' \t\n'
153+ __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
154+}
155+
156+# Generates completion reply from newline-separated possible completion words
157+# by appending a space to all of them. The result is appended to COMPREPLY.
158+# It accepts 1 to 4 arguments:
159+# 1: List of possible completion words, separated by a single newline.
160+# 2: A prefix to be added to each possible completion word (optional).
161+# 3: Generate possible completion matches for this word (optional).
162+# 4: A suffix to be appended to each possible completion word instead of
163+# the default space (optional). If specified but empty, nothing is
164+# appended.
165+__gitcomp_nl ()
166+{
167+ local IFS=$'\n'
168+ __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
169+}
170+
171+# Appends prefiltered words to COMPREPLY without any additional processing.
172+# Callers must take care of providing only words that match the current word
173+# to be completed and adding any prefix and/or suffix (trailing space!), if
174+# necessary.
175+# 1: List of newline-separated matching completion words, complete with
176+# prefix and suffix.
177+__gitcomp_direct ()
178+{
179+ local IFS=$'\n'
180+
181+ COMPREPLY+=($1)
182+}
183+
184+# Generates completion reply with compgen from newline-separated possible
185+# completion filenames.
186+# It accepts 1 to 3 arguments:
187+# 1: List of possible completion filenames, separated by a single newline.
188+# 2: A directory prefix to be added to each possible completion filename
189+# (optional).
190+# 3: Generate possible completion matches for this word (optional).
191+__gitcomp_file ()
192+{
193+ local IFS=$'\n'
194+
195+ # XXX does not work when the directory prefix contains a tilde,
196+ # since tilde expansion is not applied.
197+ # This means that COMPREPLY will be empty and Bash default
198+ # completion will be used.
199+ __gitcompadd "$1" "${2-}" "${3-$cur}" ""
200+
201+ # use a hack to enable file mode in bash < 4
202+ compopt -o filenames +o nospace 2>/dev/null ||
203+ compgen -f /non-existing-dir/ >/dev/null ||
204+ true
205+}
206+
207+# Fills the COMPREPLY array with prefiltered paths without any additional
208+# processing.
209diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
210index 54e123d632cd5cbc57215d9db7fae7b0981a01cf..db7c0068fb55d9a520478e0b46ba952dc650f816 100644
211--- a/plugins/gitfast/git-prompt.sh
212+++ b/plugins/gitfast/git-prompt.sh
213@@ -138,6 +138,7 @@ __git_ps1_show_upstream ()
214 done <<< "$output"
215
216 # parse configuration values
217+ local option
218 for option in ${GIT_PS1_SHOWUPSTREAM}; do
219 case "$option" in
220 git|svn) upstream="$option" ;;
221@@ -432,8 +433,8 @@ __git_ps1 ()
222 fi
223
224 local sparse=""
225- if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
226- [ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
227+ if [ -z "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
228+ [ -z "${GIT_PS1_OMITSPARSESTATE-}" ] &&
229 [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
230 sparse="|SPARSE"
231 fi
232@@ -542,7 +543,7 @@ __git_ps1 ()
233 u="%${ZSH_VERSION+%}"
234 fi
235
236- if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
237+ if [ -n "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
238 [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
239 h="?"
240 fi
241diff --git a/plugins/gitfast/update b/plugins/gitfast/update
242index 5311065a1103a2c6c4442f35d260d0f90e5a389c..5ebaaef3d4bea3bc8574a4c0885e4b262d983e17 100755
243--- a/plugins/gitfast/update
244+++ b/plugins/gitfast/update
245@@ -1,7 +1,7 @@
246 #!/bin/sh
247
248 url="https://raw.githubusercontent.com/felipec/git-completion"
249-version="1.2"
250+version="1.3.6"
251
252 curl -s -o _git "${url}/v${version}/git-completion.zsh" &&
253 curl -s -o git-completion.bash "${url}/v${version}/git-completion.bash" &&