Skip to content

Commit 1ce23aa

Browse files
felipecgitster
authored andcommitted
completion: add new __gitcompadd helper
The idea is to never touch the COMPREPLY variable directly. This allows other completion systems (i.e. zsh) to override __gitcompadd, and do something different instead. Also, this allows further optimizations down the line. There should be no functional changes. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0285118 commit 1ce23aa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

contrib/completion/git-completion.bash

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ _get_comp_words_by_ref ()
195195
}
196196
fi
197197

198+
__gitcompadd ()
199+
{
200+
COMPREPLY=($(compgen -W "$1" -P "$2" -S "$4" -- "$3"))
201+
}
202+
198203
# Generates completion reply with compgen, appending a space to possible
199204
# completion words, if necessary.
200205
# It accepts 1 to 4 arguments:
@@ -211,9 +216,7 @@ __gitcomp ()
211216
;;
212217
*)
213218
local IFS=$'\n'
214-
COMPREPLY=($(compgen -P "${2-}" \
215-
-W "$(__gitcomp_1 "${1-}" "${4-}")" \
216-
-- "$cur_"))
219+
__gitcompadd "$(__gitcomp_1 "${1-}" "${4-}")" "${2-}" "$cur_" ""
217220
;;
218221
esac
219222
}
@@ -230,7 +233,7 @@ __gitcomp ()
230233
__gitcomp_nl ()
231234
{
232235
local IFS=$'\n'
233-
COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
236+
__gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
234237
}
235238

236239
# Generates completion reply with compgen from newline-separated possible
@@ -1825,7 +1828,7 @@ _git_config ()
18251828
local remote="${prev#remote.}"
18261829
remote="${remote%.fetch}"
18271830
if [ -z "$cur" ]; then
1828-
COMPREPLY=("refs/heads/")
1831+
__gitcompadd "refs/heads/" "" "" ""
18291832
return
18301833
fi
18311834
__gitcomp_nl "$(__git_refs_remotes "$remote")"

0 commit comments

Comments
 (0)