Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2020-12-31 02:29:50 +0300
committerJunio C Hamano <gitster@pobox.com>2021-01-05 02:25:56 +0300
commit5a067ba9d04eebc92ad77f101b785219238f4f1e (patch)
tree5c8dd921b4344c06c65e824d180dc98186938880 /contrib
parent0e02bdc17a4d4beca06d5606a1d3020c79676d7f (diff)
completion: add proper public __git_complete
When __git_complete was introduced, it was meant to be temporarily, while a proper guideline for public shell functions was established (tentatively _GIT_complete), but since that never happened, people in the wild started to use __git_complete, even though it was marked as not public. Eight years is more than enough wait, let's mark this function as public, and make it a bit more user-friendly. So that instead of doing: __git_complete gk __gitk_main The user can do: __git_complete gk gitk And instead of: __git_complete gf _git_fetch Do: __git_complete gf git_fetch Backwards compatibility is maintained. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/completion/git-completion.bash40
1 files changed, 33 insertions, 7 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1150d4bf44..4b1f4264a6 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -29,6 +29,15 @@
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
#
+# If you have a command that is not part of git, but you would still
+# like completion, you can use __git_complete:
+#
+# __git_complete gl git_log
+#
+# Or if it's a main command (i.e. git or gitk):
+#
+# __git_complete gk gitk
+#
# Compatible with bash 3.2.57.
#
# You can set the following environment variables to influence the behavior of
@@ -3497,10 +3506,7 @@ __git_func_wrap ()
$1
}
-# Setup completion for certain functions defined above by setting common
-# variables and workarounds.
-# This is NOT a public function; use at your own risk.
-__git_complete ()
+___git_complete ()
{
local wrapper="__git_wrap${2}"
eval "$wrapper () { __git_func_wrap $2 ; }"
@@ -3508,13 +3514,33 @@ __git_complete ()
|| complete -o default -o nospace -F $wrapper $1
}
-__git_complete git __git_main
-__git_complete gitk __gitk_main
+# Setup the completion for git commands
+# 1: command or alias
+# 2: function to call (e.g. `git`, `gitk`, `git_fetch`)
+__git_complete ()
+{
+ local func
+
+ if __git_have_func $2; then
+ func=$2
+ elif __git_have_func __$2_main; then
+ func=__$2_main
+ elif __git_have_func _$2; then
+ func=_$2
+ else
+ echo "ERROR: could not find function '$2'" 1>&2
+ return 1
+ fi
+ ___git_complete $1 $func
+}
+
+___git_complete git __git_main
+___git_complete gitk __gitk_main
# The following are necessary only for Cygwin, and only are needed
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
#
if [ "$OSTYPE" = cygwin ]; then
- __git_complete git.exe __git_main
+ ___git_complete git.exe __git_main
fi