git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Custom git completion

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 29, 2010, 17:59 UTC
Message-ID
<20100129175950.GE21821@spearce.org>
In-Reply-To
<7v4om4kdt3.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > David Rhodes Clymer <david@zettazebra.com> wrote:
> >> 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.

 
Show 6 quoted lines
> 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.
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 25 in “Custom git completion”
  1. David Rhodes ClymerJan 29, 2010
  2. Shawn O. PearceJan 29, 2010
  3. Junio C HamanoJan 29, 2010
  4. Shawn O. PearceJan 29, 2010
  5. Junio C HamanoJan 29, 2010
  6. bash: support user-supplied completion scripts for user's git commandsSZEDER Gábor, Jan 29, 2010
  7. Shawn O. PearceJan 29, 2010
  8. SZEDER GáborJan 29, 2010
  9. Shawn O. PearceJan 29, 2010
  10. SZEDER GáborJan 31, 2010
  11. 0/4 bash: support user-supplied completion scripts for custom git commands and aliasesSZEDER Gábor, Feb 23, 2010
  12. 1/4 bash: improve aliased command recognitionSZEDER Gábor, Feb 23, 2010
  13. Junio C HamanoFeb 23, 2010
  14. SZEDER GáborFeb 24, 2010
  15. Junio C HamanoFeb 24, 2010
  16. 2/4 bash: support user-supplied completion scripts for user's git commandsSZEDER Gábor, Feb 23, 2010
  17. 3/4 bash: support user-supplied completion scripts for aliasesSZEDER Gábor, Feb 23, 2010
  18. 4/4 bash: completion for gitk aliasesSZEDER Gábor, Feb 23, 2010
  19. Junio C HamanoJan 29, 2010
  20. SZEDER GáborFeb 26, 2010
  21. Junio C HamanoFeb 26, 2010
  22. Shawn O. PearceFeb 26, 2010
  23. David Rhodes ClymerJan 30, 2010
  24. David Rhodes ClymerJan 30, 2010
  25. David Rhodes ClymerJan 30, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.