bash: support user-supplied completion scripts for user's git commands
commit424cce832d180843ab9b54eec3a7643948fc1afd
authorSZEDER Gábor <szeder@ira.uka.de>
Tue, 23 Feb 2010 21:02:58 +0000 (23 22:02 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Feb 2010 16:32:20 +0000 (24 08:32 -0800)
tree864e06cd95805d2a81c5c10a415d09d212350086
parentc63437cbd79e4c11ddcd06cc59f81401ae393794
bash: support user-supplied completion scripts for user's git commands

The bash completion script already provides support to complete
aliases, options and refs for aliases (if the alias can be traced back
to a supported git command by __git_aliased_command()), and the user's
custom git commands, but it does not support the options of the user's
custom git commands (of course; how could it know about the options of
a custom git command?).  Users of such custom git commands could
extend git's bash completion script by writing functions to support
their commands, but they might have issues with it: they might not
have the rights to modify a system-wide git completion script, and
they will need to track and merge upstream changes in the future.

This patch addresses this by providing means for users to supply
custom completion scriplets for their custom git commands without
modifying the main git bash completion script.

Instead of having a huge hard-coded list of command-completion
function pairs (in _git()), the completion script will figure out
which completion function to call based on the command's name.  That
is, when completing the options of 'git foo', the main completion
script will check whether the function '_git_foo' is declared, and if
declared, it will invoke that function to perform the completion.  If
such a function is not declared, it will fall back to complete file
names.  So, users will only need to provide this '_git_foo' completion
function in a separate file, source that file, and it will be used the
next time they press TAB after 'git foo '.

There are two git commands (stage and whatchanged), for which the
completion functions of other commands were used, therefore they
got their own completion function.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash