git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/10] Hide plumbing/transport commands from bash completion.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
@ 2006-11-27  8:41 ` Shawn O. Pearce
  2006-11-27  8:41 ` [PATCH 3/10] Teach bash how to complete options for git-name-rev Shawn O. Pearce
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Users generally are not going to need to invoke plumbing-level commands
from within one line shell commands.  If they are invoking these commands
then it is likely that they are glueing them together into a shell script
to perform an action, in which case bash completion for these commands is
of relatively little use.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   62 +++++++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 28bd0e3..b55431f 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -125,6 +125,58 @@ __git_complete_file ()
 	esac
 }
 
+__git_commands ()
+{
+	local i IFS=" "$'\n'
+	for i in $(git help -a|egrep '^ ')
+	do
+		case $i in
+		check-ref-format) : plumbing;;
+		commit-tree)      : plumbing;;
+		convert-objects)  : plumbing;;
+		cvsserver)        : daemon;;
+		daemon)           : daemon;;
+		fetch-pack)       : plumbing;;
+		hash-object)      : plumbing;;
+		http-*)           : transport;;
+		index-pack)       : plumbing;;
+		local-fetch)      : plumbing;;
+		mailinfo)         : plumbing;;
+		mailsplit)        : plumbing;;
+		merge-*)          : plumbing;;
+		mktree)           : plumbing;;
+		mktag)            : plumbing;;
+		pack-objects)     : plumbing;;
+		pack-redundant)   : plumbing;;
+		pack-refs)        : plumbing;;
+		parse-remote)     : plumbing;;
+		patch-id)         : plumbing;;
+		peek-remote)      : plumbing;;
+		read-tree)        : plumbing;;
+		receive-pack)     : plumbing;;
+		rerere)           : plumbing;;
+		rev-list)         : plumbing;;
+		rev-parse)        : plumbing;;
+		runstatus)        : plumbing;;
+		sh-setup)         : internal;;
+		shell)            : daemon;;
+		send-pack)        : plumbing;;
+		show-index)       : plumbing;;
+		ssh-*)            : transport;;
+		stripspace)       : plumbing;;
+		symbolic-ref)     : plumbing;;
+		unpack-file)      : plumbing;;
+		unpack-objects)   : plumbing;;
+		update-ref)       : plumbing;;
+		update-server-info) : daemon;;
+		upload-archive)   : plumbing;;
+		upload-pack)      : plumbing;;
+		write-tree)       : plumbing;;
+		*) echo $i;;
+		esac
+	done
+}
+
 __git_aliases ()
 {
 	local i IFS=$'\n'
@@ -355,11 +407,11 @@ _git ()
 	done
 
 	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
-		COMPREPLY=($(compgen \
-			-W "--git-dir= --version \
-				$(git help -a|egrep '^ ') \
-			    $(__git_aliases)" \
-			-- "${COMP_WORDS[COMP_CWORD]}"))
+		COMPREPLY=($(compgen -W "
+			--git-dir= --version --exec-path
+			$(__git_commands)
+			$(__git_aliases)
+			" -- "${COMP_WORDS[COMP_CWORD]}"))
 		return;
 	fi
 
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/10] Teach bash how to complete options for git-name-rev.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
  2006-11-27  8:41 ` [PATCH 2/10] Hide plumbing/transport commands from bash completion Shawn O. Pearce
@ 2006-11-27  8:41 ` Shawn O. Pearce
  2006-11-27  8:41 ` [PATCH 4/10] Add current branch in PS1 support to git-completion.bash Shawn O. Pearce
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b55431f..1dfb592 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -326,6 +326,12 @@ _git_merge_base ()
 	COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 }
 
+_git_name_rev ()
+{
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
+}
+
 _git_pull ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -430,6 +436,7 @@ _git ()
 	ls-tree)     _git_ls_tree ;;
 	merge)       _git_merge;;
 	merge-base)  _git_merge_base ;;
+	name-rev)    _git_name_rev ;;
 	pull)        _git_pull ;;
 	push)        _git_push ;;
 	reset)       _git_reset ;;
@@ -459,6 +466,7 @@ complete -o default            -F _git_ls_remote git-ls-remote
 complete -o default -o nospace -F _git_ls_tree git-ls-tree
 complete -o default            -F _git_merge git-merge
 complete -o default            -F _git_merge_base git-merge-base
+complete -o default            -F _git_name_rev git-name-rev
 complete -o default -o nospace -F _git_pull git-pull
 complete -o default -o nospace -F _git_push git-push
 complete -o default            -F _git_reset git-reset
@@ -479,6 +487,7 @@ complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
 complete -o default -o nospace -F _git_log git-log.exe
 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            -F _git_name_rev git-name-rev.exe
 complete -o default -o nospace -F _git_push git-push.exe
 complete -o default -o nospace -F _git_log git-show-branch.exe
 complete -o default -o nospace -F _git_log git-whatchanged.exe
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/10] Add current branch in PS1 support to git-completion.bash.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
  2006-11-27  8:41 ` [PATCH 2/10] Hide plumbing/transport commands from bash completion Shawn O. Pearce
  2006-11-27  8:41 ` [PATCH 3/10] Teach bash how to complete options for git-name-rev Shawn O. Pearce
@ 2006-11-27  8:41 ` Shawn O. Pearce
  2006-11-27 15:31   ` Sean
       [not found]   ` <20061127103111.4835bffc.seanlkml@sympatico.ca>
  2006-11-27  8:41 ` [PATCH 5/10] Teach bash how to complete git-format-patch Shawn O. Pearce
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Many users want to display the current branch name of the current git
repository as part of their PS1 prompt, much as their PS1 prompt might
also display the current working directory name.

We don't force our own PS1 onto the user.  Instead we let them craft
their own PS1 string and offer them the function __git_ps1 which they
can invoke to obtain either "" (when not in a git repository) or
"(%s)" where %s is the name of the current branch, as read from HEAD,
with the leading refs/heads/ removed.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1dfb592..a740d05 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -18,12 +18,31 @@
 #    2) Added the following line to your .bashrc:
 #        source ~/.git-completion.sh
 #
+#    3) Consider changing your PS1 to also show the current branch:
+#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
+#
+#       The argument to __git_ps1 will be displayed only if you
+#       are currently in a git repository.  The %s token will be
+#       the name of the current branch.
+#
 
 __gitdir ()
 {
 	echo "${__git_dir:-$(git rev-parse --git-dir 2>/dev/null)}"
 }
 
+__git_ps1 ()
+{
+	local b="$(git symbolic-ref HEAD 2>/dev/null)"
+	if [ -n "$b" ]; then
+		if [ -n "$1" ]; then
+			printf "$1" "${b##refs/heads/}"
+		else
+			printf " (%s)" "${b##refs/heads/}"
+		fi
+	fi
+}
+
 __git_refs ()
 {
 	local cmd i is_hash=y dir="${1:-$(__gitdir)}"
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 5/10] Teach bash how to complete git-format-patch.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
                   ` (2 preceding siblings ...)
  2006-11-27  8:41 ` [PATCH 4/10] Add current branch in PS1 support to git-completion.bash Shawn O. Pearce
@ 2006-11-27  8:41 ` Shawn O. Pearce
  2006-11-27  8:50   ` Jakub Narebski
  2006-11-27  8:41 ` [PATCH 6/10] Teach bash how to complete git-cherry-pick Shawn O. Pearce
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Provide completion for currently known long options supported by
git-format-patch as well as the revision list specification argument,
which is generally either a refname or in the form a..b.

Since _git_log was the only code that knew how to complete a..b, but
we want to start adding option support to _git_log also refactor the
a..b completion logic out into its own function.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   60 +++++++++++++++++++++++--------
 1 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index a740d05..729e5a9 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -144,6 +144,26 @@ __git_complete_file ()
 	esac
 }
 
+__git_complete_revlist ()
+{
+	local pfx cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	*...*)
+		pfx="${cur%...*}..."
+		cur="${cur#*...}"
+		COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
+		;;
+	*..*)
+		pfx="${cur%..*}.."
+		cur="${cur#*..}"
+		COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
+		;;
+	*)
+		COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
+		;;
+	esac
+}
+
 __git_commands ()
 {
 	local i IFS=" "$'\n'
@@ -290,6 +310,26 @@ _git_fetch ()
 	esac
 }
 
+_git_format_patch ()
+{
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		COMPREPLY=($(compgen -W "
+			--stdout --attach --thread
+			--output-directory
+			--numbered --start-number
+			--keep-subject
+			--signoff
+			--in-repy-to=
+			--full-index --binary
+			" -- "$cur"))
+		return
+		;;
+	esac
+	__git_complete_revlist
+}
+
 _git_ls_remote ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -303,22 +343,7 @@ _git_ls_tree ()
 
 _git_log ()
 {
-	local pfx cur="${COMP_WORDS[COMP_CWORD]}"
-	case "$cur" in
-	*...*)
-		pfx="${cur%...*}..."
-		cur="${cur#*...}"
-		COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
-		;;
-	*..*)
-		pfx="${cur%..*}.."
-		cur="${cur#*..}"
-		COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
-		;;
-	*)
-		COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
-		;;
-	esac
+	__git_complete_revlist
 }
 
 _git_merge ()
@@ -450,6 +475,7 @@ _git ()
 	diff)        _git_diff ;;
 	diff-tree)   _git_diff_tree ;;
 	fetch)       _git_fetch ;;
+	format-patch) _git_format_patch ;;
 	log)         _git_log ;;
 	ls-remote)   _git_ls_remote ;;
 	ls-tree)     _git_ls_tree ;;
@@ -480,6 +506,7 @@ complete -o default            -F _git_checkout git-checkout
 complete -o default -o nospace -F _git_diff git-diff
 complete -o default            -F _git_diff_tree git-diff-tree
 complete -o default -o nospace -F _git_fetch git-fetch
+complete -o default -o nospace -F _git_format_patch git-format-patch
 complete -o default -o nospace -F _git_log git-log
 complete -o default            -F _git_ls_remote git-ls-remote
 complete -o default -o nospace -F _git_ls_tree git-ls-tree
@@ -503,6 +530,7 @@ complete -o default            -F _git_branch git-branch.exe
 complete -o default -o nospace -F _git_cat_file git-cat-file.exe
 complete -o default -o nospace -F _git_diff git-diff.exe
 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
+complete -o default -o nospace -F _git_format_patch git-format-patch.exe
 complete -o default -o nospace -F _git_log git-log.exe
 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
 complete -o default            -F _git_merge_base git-merge-base.exe
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 6/10] Teach bash how to complete git-cherry-pick.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
                   ` (3 preceding siblings ...)
  2006-11-27  8:41 ` [PATCH 5/10] Teach bash how to complete git-format-patch Shawn O. Pearce
@ 2006-11-27  8:41 ` Shawn O. Pearce
  2006-11-27  8:42 ` [PATCH 7/10] Teach bash how to complete git-rebase Shawn O. Pearce
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 729e5a9..02a60a0 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -269,6 +269,21 @@ _git_checkout ()
 	COMPREPLY=($(compgen -W "-l -b $(__git_refs)" -- "$cur"))
 }
 
+_git_cherry_pick ()
+{
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		COMPREPLY=($(compgen -W "
+			--edit --no-commit
+			" -- "$cur"))
+		;;
+	*)
+		COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
+		;;
+	esac
+}
+
 _git_diff ()
 {
 	__git_complete_file
@@ -472,6 +487,7 @@ _git ()
 	branch)      _git_branch ;;
 	cat-file)    _git_cat_file ;;
 	checkout)    _git_checkout ;;
+	cherry-pick) _git_cherry_pick ;;
 	diff)        _git_diff ;;
 	diff-tree)   _git_diff_tree ;;
 	fetch)       _git_fetch ;;
@@ -503,6 +519,7 @@ complete -o default            -F _gitk gitk
 complete -o default            -F _git_branch git-branch
 complete -o default -o nospace -F _git_cat_file git-cat-file
 complete -o default            -F _git_checkout git-checkout
+complete -o default            -F _git_cherry_pick git-cherry-pick
 complete -o default -o nospace -F _git_diff git-diff
 complete -o default            -F _git_diff_tree git-diff-tree
 complete -o default -o nospace -F _git_fetch git-fetch
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 7/10] Teach bash how to complete git-rebase.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
                   ` (4 preceding siblings ...)
  2006-11-27  8:41 ` [PATCH 6/10] Teach bash how to complete git-cherry-pick Shawn O. Pearce
@ 2006-11-27  8:42 ` Shawn O. Pearce
  2006-11-27  8:42 ` [PATCH 8/10] Teach bash about git log/show/whatchanged options Shawn O. Pearce
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

As git-rebase is a popular command bash should know how to complete
reference names and its long options.  We only support completions
which make sense given the current state of the repository, that
way users don't get shown --continue/--skip/--abort on the first
execution.

Also added support for long option --strategy to git-merge, as I
missed that option earlier and just noticed it while implementing
git-rebase.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   38 ++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 02a60a0..a61b6b9 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -367,16 +367,16 @@ _git_merge ()
 	case "$cur" in
 	--*)
 		COMPREPLY=($(compgen -W "
-			--no-commit --no-summary --squash
+			--no-commit --no-summary --squash --strategy
 			" -- "$cur"))
 		return
 	esac
-	if [ $COMP_CWORD -gt 1 -a X-s = "X${COMP_WORDS[COMP_CWORD-1]}" ]
-	then
+	case "${COMP_WORDS[COMP_CWORD-1]}" in
+	-s|--strategy)
 		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
-	else
-		COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
-	fi
+		return
+	esac
+	COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 }
 
 _git_merge_base ()
@@ -443,6 +443,30 @@ _git_push ()
 	esac
 }
 
+_git_rebase ()
+{
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	if [ -d .dotest ]; then
+		COMPREPLY=($(compgen -W "
+			--continue --skip --abort
+			" -- "$cur"))
+		return
+	fi
+	case "$cur" in
+	--*)
+		COMPREPLY=($(compgen -W "
+			--onto --merge --strategy
+			" -- "$cur"))
+		return
+	esac
+	case "${COMP_WORDS[COMP_CWORD-1]}" in
+	-s|--strategy)
+		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
+		return
+	esac
+	COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
+}
+
 _git_reset ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -500,6 +524,7 @@ _git ()
 	name-rev)    _git_name_rev ;;
 	pull)        _git_pull ;;
 	push)        _git_push ;;
+	rebase)      _git_rebase ;;
 	reset)       _git_reset ;;
 	show)        _git_show ;;
 	show-branch) _git_log ;;
@@ -532,6 +557,7 @@ complete -o default            -F _git_merge_base git-merge-base
 complete -o default            -F _git_name_rev git-name-rev
 complete -o default -o nospace -F _git_pull git-pull
 complete -o default -o nospace -F _git_push git-push
+complete -o default            -F _git_rebase git-rebase
 complete -o default            -F _git_reset git-reset
 complete -o default            -F _git_show git-show
 complete -o default -o nospace -F _git_log git-show-branch
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 8/10] Teach bash about git log/show/whatchanged options.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
                   ` (5 preceding siblings ...)
  2006-11-27  8:42 ` [PATCH 7/10] Teach bash how to complete git-rebase Shawn O. Pearce
@ 2006-11-27  8:42 ` Shawn O. Pearce
  2006-11-27  8:42 ` [PATCH 9/10] Allow completion of --committer and --author arguments to git log Shawn O. Pearce
  2006-11-27  8:42 ` [PATCH 10/10] Support bash completion of refs/remote Shawn O. Pearce
  8 siblings, 0 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Typing out options to git log/show/whatchanged can take a while, but
we can easily complete them with bash.  So list the most common ones,
especially --pretty=online|short|medium|... so that users don't need
to type everything out.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   34 ++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index a61b6b9..8acfb09 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -358,6 +358,29 @@ _git_ls_tree ()
 
 _git_log ()
 {
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--pretty=*)
+		COMPREPLY=($(compgen -W "
+			oneline short medium full fuller email raw
+			" -- "${cur##--pretty=}"))
+		return
+		;;
+	--*)
+		COMPREPLY=($(compgen -W "
+			--max-count= --max-age= --since= --after=
+			--min-age= --before= --until=
+			--root --not --topo-order --date-order
+			--no-merges
+			--abbrev-commit --abbrev=
+			--relative-date
+			--author= --committer= --grep=
+			--all-match
+			--pretty= --name-status --name-only
+			" -- "$cur"))
+		return
+		;;
+	esac
 	__git_complete_revlist
 }
 
@@ -474,12 +497,6 @@ _git_reset ()
 	COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
 }
 
-_git_show ()
-{
-	local cur="${COMP_WORDS[COMP_CWORD]}"
-	COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
-}
-
 _git ()
 {
 	local i c=1 command __git_dir
@@ -526,7 +543,7 @@ _git ()
 	push)        _git_push ;;
 	rebase)      _git_rebase ;;
 	reset)       _git_reset ;;
-	show)        _git_show ;;
+	show)        _git_log ;;
 	show-branch) _git_log ;;
 	whatchanged) _git_log ;;
 	*)           COMPREPLY=() ;;
@@ -559,7 +576,7 @@ complete -o default -o nospace -F _git_pull git-pull
 complete -o default -o nospace -F _git_push git-push
 complete -o default            -F _git_rebase git-rebase
 complete -o default            -F _git_reset git-reset
-complete -o default            -F _git_show git-show
+complete -o default            -F _git_log git-show
 complete -o default -o nospace -F _git_log git-show-branch
 complete -o default -o nospace -F _git_log git-whatchanged
 
@@ -579,6 +596,7 @@ 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            -F _git_name_rev git-name-rev.exe
 complete -o default -o nospace -F _git_push git-push.exe
+complete -o default -o nospace -F _git_log git-show.exe
 complete -o default -o nospace -F _git_log git-show-branch.exe
 complete -o default -o nospace -F _git_log git-whatchanged.exe
 fi
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 9/10] Allow completion of --committer and --author arguments to git log.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
                   ` (6 preceding siblings ...)
  2006-11-27  8:42 ` [PATCH 8/10] Teach bash about git log/show/whatchanged options Shawn O. Pearce
@ 2006-11-27  8:42 ` Shawn O. Pearce
  2006-11-27 10:28   ` Nicolas Vilz
  2006-11-27 20:20   ` Junio C Hamano
  2006-11-27  8:42 ` [PATCH 10/10] Support bash completion of refs/remote Shawn O. Pearce
  8 siblings, 2 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

This is just a cute hack, but we can (easily) complete the parameter
to --author or --committer in bash by asking for all possible authors
or committers in this project from git log and offering them up as
valid choices.

We replace spaces with dots as this prevents names with spaces from
appearing as two parameters rather than one, yet it still matches the
space in the field.

Currently my Mac OS X system takes ~5 seconds to compute the completions
for --author on git.git and ~4 seconds to compute the completions for
--committer on same.  I imagine it would take longer on more active
projects, but its a good way to see if the name you are entering is
going to be unique or not.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8acfb09..b456a3b 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -360,6 +360,26 @@ _git_log ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
 	case "$cur" in
+	--committer=*)
+		COMPREPLY=($(compgen -W "$(git log --pretty=raw --all \
+			| sed -n -e "/^committer /{
+				s/^committer //
+				s/ <.*//
+				s/ /./g
+				p
+			}")" -- "${cur##--committer=}"))
+		return
+		;;
+	--author=*)
+		COMPREPLY=($(compgen -W "$(git log --pretty=raw --all \
+			| sed -n -e "/^author /{
+				s/^author //
+				s/ <.*//
+				s/ /./g
+				p
+			}")" -- "${cur##--author=}"))
+		return
+		;;
 	--pretty=*)
 		COMPREPLY=($(compgen -W "
 			oneline short medium full fuller email raw
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 10/10] Support bash completion of refs/remote.
       [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
                   ` (7 preceding siblings ...)
  2006-11-27  8:42 ` [PATCH 9/10] Allow completion of --committer and --author arguments to git log Shawn O. Pearce
@ 2006-11-27  8:42 ` Shawn O. Pearce
  8 siblings, 0 replies; 19+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Now that people are really likely to start using separate remotes
(due to the default in git-clone changing) we should support ref
completion for these refs in as many commands as possible.

While we are working on this routine we should use for-each-ref
to obtain a list of local refs, as this should run faster than
peek-remote as it does not need to dereference tag objects in
order to produce the list of refs back to us.  It should also
be more friendly to users of StGIT as we won't generate a list
of the StGIT metadata refs.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b456a3b..df67f8e 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -47,16 +47,26 @@ __git_refs ()
 {
 	local cmd i is_hash=y dir="${1:-$(__gitdir)}"
 	if [ -d "$dir" ]; then
-		cmd=git-peek-remote
-	else
-		cmd=git-ls-remote
+		if [ -e "$dir/HEAD" ]; then echo HEAD; fi
+		for i in $(git --git-dir="$dir" \
+			for-each-ref --format='%(refname)' \
+			refs/tags refs/heads refs/remotes); do
+			case "$i" in
+				refs/tags/*)    echo "${i#refs/tags/}" ;;
+				refs/heads/*)   echo "${i#refs/heads/}" ;;
+				refs/remotes/*) echo "${i#refs/remotes/}" ;;
+				*)              echo "$i" ;;
+			esac
+		done
+		return
 	fi
-	for i in $($cmd "$dir" 2>/dev/null); do
+	for i in $(git-ls-remote "$dir" 2>/dev/null); do
 		case "$is_hash,$i" in
 		y,*) is_hash=n ;;
 		n,*^{}) is_hash=y ;;
 		n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
 		n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
+		n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
 		n,*) is_hash=y; echo "$i" ;;
 		esac
 	done
-- 

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 5/10] Teach bash how to complete git-format-patch.
  2006-11-27  8:41 ` [PATCH 5/10] Teach bash how to complete git-format-patch Shawn O. Pearce
@ 2006-11-27  8:50   ` Jakub Narebski
  0 siblings, 0 replies; 19+ messages in thread
From: Jakub Narebski @ 2006-11-27  8:50 UTC (permalink / raw)
  To: git

Shawn O. Pearce wrote:

> +                       --in-repy-to=

--in-reply-to I think. And why his sole option has '='?
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 9/10] Allow completion of --committer and --author arguments to git log.
  2006-11-27  8:42 ` [PATCH 9/10] Allow completion of --committer and --author arguments to git log Shawn O. Pearce
@ 2006-11-27 10:28   ` Nicolas Vilz
  2006-11-27 16:46     ` Shawn Pearce
  2006-11-27 20:20   ` Junio C Hamano
  1 sibling, 1 reply; 19+ messages in thread
From: Nicolas Vilz @ 2006-11-27 10:28 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git

On Mon, Nov 27, 2006 at 03:42:28AM -0500, Shawn O. Pearce wrote:
> This is just a cute hack, but we can (easily) complete the parameter
> to --author or --committer in bash by asking for all possible authors
> or committers in this project from git log and offering them up as
> valid choices.
> 
> We replace spaces with dots as this prevents names with spaces from
> appearing as two parameters rather than one, yet it still matches the
> space in the field.
is it hard to train bash-completion to use "" and spaces instead of 
replacing spaces by dots? Besides, great feature, thank you for that... 
that's very handy.

Sincerly

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/10] Add current branch in PS1 support to git-completion.bash.
  2006-11-27  8:41 ` [PATCH 4/10] Add current branch in PS1 support to git-completion.bash Shawn O. Pearce
@ 2006-11-27 15:31   ` Sean
       [not found]   ` <20061127103111.4835bffc.seanlkml@sympatico.ca>
  1 sibling, 0 replies; 19+ messages in thread
From: Sean @ 2006-11-27 15:31 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git

On Mon, 27 Nov 2006 03:41:28 -0500
"Shawn O. Pearce" <spearce@spearce.org> wrote:

> Many users want to display the current branch name of the current git
> repository as part of their PS1 prompt, much as their PS1 prompt might
> also display the current working directory name.
> 
> We don't force our own PS1 onto the user.  Instead we let them craft
> their own PS1 string and offer them the function __git_ps1 which they
> can invoke to obtain either "" (when not in a git repository) or
> "(%s)" where %s is the name of the current branch, as read from HEAD,
> with the leading refs/heads/ removed.

Suppose it doesn't hurt to include support for this in git completion
scripts.  It doesn't look like __git_ps1 is a proper name though,
perhaps __git_branch or __git_current_branch would be better?


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 9/10] Allow completion of --committer and --author arguments to git log.
  2006-11-27 10:28   ` Nicolas Vilz
@ 2006-11-27 16:46     ` Shawn Pearce
  0 siblings, 0 replies; 19+ messages in thread
From: Shawn Pearce @ 2006-11-27 16:46 UTC (permalink / raw)
  To: Nicolas Vilz; +Cc: Junio C Hamano, git

Nicolas Vilz <niv@iaglans.de> wrote:
> On Mon, Nov 27, 2006 at 03:42:28AM -0500, Shawn O. Pearce wrote:
> > This is just a cute hack, but we can (easily) complete the parameter
> > to --author or --committer in bash by asking for all possible authors
> > or committers in this project from git log and offering them up as
> > valid choices.
> > 
> > We replace spaces with dots as this prevents names with spaces from
> > appearing as two parameters rather than one, yet it still matches the
> > space in the field.
>
> is it hard to train bash-completion to use "" and spaces instead of 
> replacing spaces by dots? Besides, great feature, thank you for that... 
> that's very handy.

I tried.  Bash did not listen.  :-)

I tried "", '', \<sp>.  None of them carried into the completion.
Obviously I was doing something wrong, but right now I don't know
what that was.  I spent 22 minutes on it and just caved in with
dots when it worked and nothing else did.

-- 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/10] Add current branch in PS1 support to git-completion.bash.
       [not found]   ` <20061127103111.4835bffc.seanlkml@sympatico.ca>
@ 2006-11-27 16:51     ` Shawn Pearce
  2006-11-27 17:26       ` Sean
       [not found]       ` <20061127122653.3e801d7a.seanlkml@sympatico.ca>
  0 siblings, 2 replies; 19+ messages in thread
From: Shawn Pearce @ 2006-11-27 16:51 UTC (permalink / raw)
  To: Sean; +Cc: Junio C Hamano, git

Sean <seanlkml@sympatico.ca> wrote:
> On Mon, 27 Nov 2006 03:41:28 -0500
> "Shawn O. Pearce" <spearce@spearce.org> wrote:
> 
> > Many users want to display the current branch name of the current git
> > repository as part of their PS1 prompt, much as their PS1 prompt might
> > also display the current working directory name.
> > 
> > We don't force our own PS1 onto the user.  Instead we let them craft
> > their own PS1 string and offer them the function __git_ps1 which they
> > can invoke to obtain either "" (when not in a git repository) or
> > "(%s)" where %s is the name of the current branch, as read from HEAD,
> > with the leading refs/heads/ removed.
> 
> Suppose it doesn't hurt to include support for this in git completion
> scripts.  It doesn't look like __git_ps1 is a proper name though,
> perhaps __git_branch or __git_current_branch would be better?

I actually started with the name __git_current_branch but changed
my mind on that and went with __git_ps1.

My rationale at the time was probably not correct (it was early this
morning) but I figured that the current branch name is "master"
while __git_ps1 prints " (master)".  Therefore __git_ps1 is not
really printing the current branch, its printing the current branch
and other stuff.  So I went with a name which implied its purpose.

-- 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/10] Add current branch in PS1 support to git-completion.bash.
  2006-11-27 16:51     ` Shawn Pearce
@ 2006-11-27 17:26       ` Sean
       [not found]       ` <20061127122653.3e801d7a.seanlkml@sympatico.ca>
  1 sibling, 0 replies; 19+ messages in thread
From: Sean @ 2006-11-27 17:26 UTC (permalink / raw)
  To: Shawn Pearce; +Cc: Junio C Hamano, git

On Mon, 27 Nov 2006 11:51:23 -0500
Shawn Pearce <spearce@spearce.org> wrote:

> I actually started with the name __git_current_branch but changed
> my mind on that and went with __git_ps1.
> 
> My rationale at the time was probably not correct (it was early this
> morning) but I figured that the current branch name is "master"
> while __git_ps1 prints " (master)".  Therefore __git_ps1 is not
> really printing the current branch, its printing the current branch
> and other stuff.  So I went with a name which implied its purpose.

Ahh, I had missed that, it makes some sense.  Although it goes a bit
against the commit message that the user is free to construct whatever
PS1 format they like (ie. they're stuck with parenthesis around the
branch name).

Just thinking out loud, what about allowing __git_ps1 to take a
format string of its own?  It could parse options like  "(\b)"
to mean git branch surrounded by parenthesis.  But you could
also do "[\b]" or "!\b" if you preferred.

Then adding additional options would be easy, like "\r" for
repo relative path etc... and the user really could create just
about any git prompt they wanted.  Of course, if __git_ps1
sees it's not in a git directory, it would always return an
empty string.

But that's maybe all too complicated to be worthwhile.  It's
something that could be considered for the git --show-ps1 option
though.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/10] Add current branch in PS1 support to git-completion.bash.
       [not found]       ` <20061127122653.3e801d7a.seanlkml@sympatico.ca>
@ 2006-11-27 17:31         ` Shawn Pearce
  2006-11-27 17:45           ` Sean
  0 siblings, 1 reply; 19+ messages in thread
From: Shawn Pearce @ 2006-11-27 17:31 UTC (permalink / raw)
  To: Sean; +Cc: Junio C Hamano, git

Sean <seanlkml@sympatico.ca> wrote:
> On Mon, 27 Nov 2006 11:51:23 -0500
> Shawn Pearce <spearce@spearce.org> wrote:
> 
> > I actually started with the name __git_current_branch but changed
> > my mind on that and went with __git_ps1.
> > 
> > My rationale at the time was probably not correct (it was early this
> > morning) but I figured that the current branch name is "master"
> > while __git_ps1 prints " (master)".  Therefore __git_ps1 is not
> > really printing the current branch, its printing the current branch
> > and other stuff.  So I went with a name which implied its purpose.
> 
> Ahh, I had missed that, it makes some sense.  Although it goes a bit
> against the commit message that the user is free to construct whatever
> PS1 format they like (ie. they're stuck with parenthesis around the
> branch name).
> 
> Just thinking out loud, what about allowing __git_ps1 to take a
> format string of its own?  It could parse options like  "(\b)"
> to mean git branch surrounded by parenthesis.  But you could
> also do "[\b]" or "!\b" if you preferred.

I did that.  :-)

If you read the implementation of __git_ps1 the default format is
" (%s)" but you can pass anything you want as the first parameter.
 
-- 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/10] Add current branch in PS1 support to git-completion.bash.
  2006-11-27 17:31         ` Shawn Pearce
@ 2006-11-27 17:45           ` Sean
  0 siblings, 0 replies; 19+ messages in thread
From: Sean @ 2006-11-27 17:45 UTC (permalink / raw)
  To: Shawn Pearce; +Cc: Junio C Hamano, git

On Mon, 27 Nov 2006 12:31:36 -0500
Shawn Pearce <spearce@spearce.org> wrote:

> I did that.  :-)
> 
> If you read the implementation of __git_ps1 the default format is
> " (%s)" but you can pass anything you want as the first parameter.

lol, you're good.  I'm back to thinking it's slightly misnamed though,
as that %s can only ever mean branch.  But it's really a minor nit,
sorry for the noise.  Good work.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 9/10] Allow completion of --committer and --author arguments to git log.
  2006-11-27  8:42 ` [PATCH 9/10] Allow completion of --committer and --author arguments to git log Shawn O. Pearce
  2006-11-27 10:28   ` Nicolas Vilz
@ 2006-11-27 20:20   ` Junio C Hamano
  2006-11-27 20:49     ` Shawn Pearce
  1 sibling, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2006-11-27 20:20 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: git

"Shawn O. Pearce" <spearce@spearce.org> writes:

> This is just a cute hack, but we can (easily) complete the parameter
> to --author or --committer in bash by asking for all possible authors
> or committers in this project from git log and offering them up as
> valid choices.

Easily but slowly ;-).  Try this in the kernel repository

	git log --author=Andre<TAB>

and watch the paint dry.  You might want to have an extra shell
to run top before you hit the TAB key.

It indeed is cute, but I think most people would wonder if the
terminal went dead, especially without any progress indicators.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 9/10] Allow completion of --committer and --author arguments to git log.
  2006-11-27 20:20   ` Junio C Hamano
@ 2006-11-27 20:49     ` Shawn Pearce
  0 siblings, 0 replies; 19+ messages in thread
From: Shawn Pearce @ 2006-11-27 20:49 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <junkio@cox.net> wrote:
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > This is just a cute hack, but we can (easily) complete the parameter
> > to --author or --committer in bash by asking for all possible authors
> > or committers in this project from git log and offering them up as
> > valid choices.
> 
> Easily but slowly ;-).  Try this in the kernel repository
> 
> 	git log --author=Andre<TAB>
> 
> and watch the paint dry.  You might want to have an extra shell
> to run top before you hit the TAB key.

When I put that in there I was thinking about how slowly that would
run on the kernel repository.  But I think its useful for git commit
--author, even if it is a tad turtleish.  I'm considering creating
a cache of names under .git/ and only dynamically generate the log
entries which are newer than the cache head.  That way we're only
wading through the most recent commits to build up the completion
set.

Apparently the bottleneck is bash.  If I add in | sort | uniq to
the end of the sed then I can generate author completions in about 7
seconds for the kernel repository.  Without them it is taking about
30 seconds.  (Both approximate as I just counted it out in my head.)

You can also see this in top.  We spend a bit of time in both git
and sed, then suddenly bash takes over for a while as it makes the
resulting list unique.

Using perl (instead of sed | sort | uniq) appears to improve things
slightly, but I'm getting some odd results that I don't have time
to debug right now.

> It indeed is cute, but I think most people would wonder if the
> terminal went dead, especially without any progress indicators.

Yes.  And in completion support mode you cannot give progress.  :-(

-- 

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2006-11-27 20:49 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <de7beb117fb963e68e1085b773593be326ffd495.1164616814.git.spearce@spearce.org>
2006-11-27  8:41 ` [PATCH 2/10] Hide plumbing/transport commands from bash completion Shawn O. Pearce
2006-11-27  8:41 ` [PATCH 3/10] Teach bash how to complete options for git-name-rev Shawn O. Pearce
2006-11-27  8:41 ` [PATCH 4/10] Add current branch in PS1 support to git-completion.bash Shawn O. Pearce
2006-11-27 15:31   ` Sean
     [not found]   ` <20061127103111.4835bffc.seanlkml@sympatico.ca>
2006-11-27 16:51     ` Shawn Pearce
2006-11-27 17:26       ` Sean
     [not found]       ` <20061127122653.3e801d7a.seanlkml@sympatico.ca>
2006-11-27 17:31         ` Shawn Pearce
2006-11-27 17:45           ` Sean
2006-11-27  8:41 ` [PATCH 5/10] Teach bash how to complete git-format-patch Shawn O. Pearce
2006-11-27  8:50   ` Jakub Narebski
2006-11-27  8:41 ` [PATCH 6/10] Teach bash how to complete git-cherry-pick Shawn O. Pearce
2006-11-27  8:42 ` [PATCH 7/10] Teach bash how to complete git-rebase Shawn O. Pearce
2006-11-27  8:42 ` [PATCH 8/10] Teach bash about git log/show/whatchanged options Shawn O. Pearce
2006-11-27  8:42 ` [PATCH 9/10] Allow completion of --committer and --author arguments to git log Shawn O. Pearce
2006-11-27 10:28   ` Nicolas Vilz
2006-11-27 16:46     ` Shawn Pearce
2006-11-27 20:20   ` Junio C Hamano
2006-11-27 20:49     ` Shawn Pearce
2006-11-27  8:42 ` [PATCH 10/10] Support bash completion of refs/remote Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).