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

[FYI PATCH] bash completion: alias 'g' to 'git' with completion

From
Thomas Rast <trast@student.ethz.ch>
Date
Oct 3, 2008, 16:35 UTC
Message-ID
<1223051705-30347-1-git-send-email-trast@student.ethz.ch>
In-Reply-To
<fc113d400810030825l75f9451dwc4cbf68807be0b5b@mail.gmail.com>
---
Rob Sanheim wrote:
Show 9 quoted lines
> On Thu, Oct 2, 2008 at 11:10 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
> > No, you'll need to alias 'g' to git in bash, and then if you still
> > want completion you'll need to also register the compgen to call
> > _git completion routine.  Its two lines:
> >
> >        alias g=git
> >        complete -o default -o nospace -F _git g
>
> Thanks, that did it.

Actually it's not enough, you need to teach fetch, pull and push to recognise the new alias too, as in this patch. I do wonder if there's a better approach to those functions however, so that the "obvious" fix suggested by Shawn would work.

- Thomas
 contrib/completion/git-completion.bash |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 7284c3b..547e735 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -789,7 +789,7 @@ _git_fetch ()
 	git-fetch*,1)
 		__gitcomp "$(__git_remotes)"
 		;;
-	git,2)
+	git,2|g,2)
 		__gitcomp "$(__git_remotes)"
 		;;
 	*)
@@ -1053,7 +1053,7 @@ _git_pull ()
 	git-pull*,1)
 		__gitcomp "$(__git_remotes)"
 		;;
-	git,2)
+	git,2|g,2)
 		__gitcomp "$(__git_remotes)"
 		;;
 	*)
@@ -1075,7 +1075,7 @@ _git_push ()
 	git-push*,1)
 		__gitcomp "$(__git_remotes)"
 		;;
-	git,2)
+	git,2|g,2)
 		__gitcomp "$(__git_remotes)"
 		;;
 	*)
@@ -1717,6 +1717,7 @@ _gitk ()
 }
 
 complete -o default -o nospace -F _git git
+complete -o default -o nospace -F _git g
 complete -o default -o nospace -F _gitk gitk
 
 # The following are necessary only for Cygwin, and only are needed
-- 
1.6.0.2.771.g3967
Previous: Rob SanheimNext: SZEDER Gábor
Message 4 of 6 in “alias g to git in .gitconfig?”
  1. Rob SanheimOct 3, 2008
  2. Shawn O. PearceOct 3, 2008
  3. Rob SanheimOct 3, 2008
  4. bash completion: alias 'g' to 'git' with completionThomas Rast, Oct 3, 2008
  5. bash: remove fetch, push, pull dashed form leftoversSZEDER Gábor, Oct 3, 2008
  6. Thomas RastOct 3, 2008

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.