Thread (3 messages) flat view 3 messages, 3 authors, 2016-06-15

Re: Custom git completion

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:48:07

Junio C Hamano [off-list ref] wrote:
"Shawn O. Pearce" [off-list ref] writes:
quoted
David Rhodes Clymer [off-list ref] wrote:
quoted
Unless I read it incorrectly, the completion script included with
git-core does not make it easy for users to write completion scripts
for custom git commands. I can extend git itself by creating a command
"git-foo", and placing it in my path.
git config --global alias.foo /home/me/bin/my-git-foo

git foo will now complete correctly.  No need to modify the
completion code.
Yes.  Aliases and custom subcommands are found from 'git help" output just
fine (you need to install new subcommand in exec-path).

But.

How does the completion code learn what options and arguments such aliases
and subcommands (e.g. "git foo") take without being told?
Sure.  But the patch offered by the original poster also suffered
from this problem, it didn't know how to complete arguments for
the subcommand.

 
An alias that uses another git subcommand (i.e. the ones that do not start
with a bang "!") seems to be handled correctly, but one of my aliases is
this:

    [alias]
	lgm = "!sh -c 'GIT_NOTES_REF=refs/notes/amlog git log \"$@\" || :' -"
Doing this is difficult, because its hard to parse that string and
do completion on it.  On the other hand, we could do something like:

  [completion]
  	lgm = log

and have `git lgm` complete using the same rules as `git log`.
Its somewhat ugly though...
 
-- 
Shawn.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help