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

Re: [PATCH] Contributed bash completion support for core Git tools.

From
Shawn Pearce <spearce@spearce.org>
Date
Sep 18, 2006, 17:42 UTC
Message-ID
<20060918174225.GC31140@spearce.org>
In-Reply-To
<7virjlr3am.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
Show 14 quoted lines
> Shawn Pearce <spearce@spearce.org> writes:
> 
> > +_git_log ()
> > +{
> > +...
> > +}
> > +...
> > +_git_whatchanged ()
> > +{
> > +...
> > +}
> 
> These two look the same.  Probably not very easy to maintain in
> the long run.
They are the same.
 
> It would be nice to have git-show as well but it usually does
> not take ranges unlike these two. It is more like "git branch"
> from completion purposes.
Like this?  :-)

-- >8 -- Consolidated git_log and git_whatchanged; added git_show.

Minor requests from Junio: Consolidate the identical implementations of git_log and git_whatchanged, especially since these two commands take pretty much identical arguments. This should make the completion package a little easier to maintain.

Also added branch name completion for git-show. I tried to implement --pretty=oneline (etc.) but am apparently missing something as bash did not want to complete it through the registered completion routine, so that's still unsupported.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/bash-git-completion.sh |   21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/contrib/bash-git-completion.sh b/contrib/bash-git-completion.sh
index 4800185..e8cf6bb 100644
--- a/contrib/bash-git-completion.sh
+++ b/contrib/bash-git-completion.sh
@@ -254,19 +254,10 @@ _git_push ()
 	esac
 }
 
-_git_whatchanged ()
+_git_show ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
-	case "$cur" in
-	*..*)
-		local pfx=$(echo "$cur" | sed 's/\.\..*$/../')
-		cur=$(echo "$cur" | sed 's/^.*\.\.//')
-		COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs .)" -- "$cur"))
-		;;
-	*)
-		COMPREPLY=($(compgen -W "$(__git_refs .)" -- "$cur"))
-		;;
-	esac
+	COMPREPLY=($(compgen -W "$(__git_refs .)" -- "$cur"))
 }
 
 _git ()
@@ -288,7 +279,8 @@ _git ()
 		ls-tree)     _git_ls_tree ;;
 		pull)        _git_pull ;;
 		push)        _git_push ;;
-		whatchanged) _git_whatchanged ;;
+		show)        _git_show ;;
+		whatchanged) _git_log ;;
 		*)           COMPREPLY=() ;;
 		esac
 	fi
@@ -314,7 +306,8 @@ complete -o default -o nospace -F _git_l
 complete -o default            -F _git_merge_base git-merge-base
 complete -o default -o nospace -F _git_pull git-pull
 complete -o default -o nospace -F _git_push git-push
-complete -o default -o nospace -F _git_whatchanged git-whatchanged
+complete -o default            -F _git_show git-show
+complete -o default -o nospace -F _git_log git-whatchanged
 
 # The following are necessary only for Cygwin, and only are needed
 # when the user has tab-completed the executable name and consequently
@@ -327,4 +320,4 @@ complete -o default -o nospace -F _git_l
 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
 complete -o default            -F _git_merge_base git-merge-base.exe
 complete -o default -o nospace -F _git_push git-push.exe
-complete -o default -o nospace -F _git_whatchanged git-whatchanged.exe
+complete -o default -o nospace -F _git_log git-whatchanged.exe
-- 
1.4.2.1.ga817
Previous: Junio C HamanoNext: Sebastian Harl
Message 9 of 11 in “Contributed bash completion support for core Git tools.”
  1. Contributed bash completion support for core Git tools.Shawn Pearce, Sep 18, 2006
  2. Junio C HamanoSep 18, 2006
  3. Shawn PearceSep 18, 2006
  4. Junio C HamanoSep 28, 2006
  5. Shawn PearceSep 28, 2006
  6. Johannes SchindelinSep 18, 2006
  7. Shawn PearceSep 18, 2006
  8. Junio C HamanoSep 18, 2006
  9. Shawn PearceSep 18, 2006
  10. Sebastian HarlSep 18, 2006
  11. Shawn PearceSep 18, 2006

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.