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

Custom git completion

From
David Rhodes Clymer <david@zettazebra.com>
Date
Jan 29, 2010, 12:57 UTC
Message-ID
<9b69cfcf1001290457s6b7fad6cs5a915f16a11f5782@mail.gmail.com>

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. The command can then be used like so: "git foo". However, if I want to add command completion for that command without modifying (I may not have permission) or duplicating the system git completion, I can't write a completion script which matches works on "git foo", only "git-foo", which is not how I would ever call the script.

Anyway, so I made a simple modification which looks for completion code for custom commands, and calls that as appropriate. If the attached patch (or something like it) were applied to the git completion script, it would be awfully handy.

-davidc
ps. I'm not subscribed to the list, so please copy me on any replies, thanks!

--- /etc/bash_completion.d/git.orig 2010-01-12 14:50:16.000000000 -0500 +++ /etc/bash_completion.d/git 2010-01-12 15:28:27.000000000 -0500

@@ -1403,7 +1403,10 @@
 	svn)         _git_svn ;;
 	tag)         _git_tag ;;
 	whatchanged) _git_log ;;
-	*)           COMPREPLY=() ;;
+	*)
+    COMPREPLY=()
+    $(complete -p |awk '/ '"git-${command}"'$/{print $(NF-1)}')
+  ;;
 	esac
 }
 
Next: Shawn O. Pearce
Message 1 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.