All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bash: complete full refs
@ 2008-11-27 13:35 SZEDER Gábor
  2008-11-27 21:29 ` Shawn O. Pearce
  0 siblings, 1 reply; 4+ messages in thread
From: SZEDER Gábor @ 2008-11-27 13:35 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: git, SZEDER Gábor

Sometimes it's handy to complete full refs, e.g. the user has some
refs outside of refs/{heads,remotes,tags} or the user wants to
complete some git command's special refs (like 'git show
refs/bisect/bad').

To do that, we check whether the ref to be completed starts with
'refs'.  If it does, then we offer full refs for completion; otherwise
everything works as usual.

This way the impact on the common case is fairly small (hopefully not
many users have branches or tags starting with 'refs'), and in the
special case the cost of typing out 'refs' is bearable.

While at it, also remove the unused 'cmd' variable from '__git_refs'.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0ee071b..39bf18b 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -188,11 +188,22 @@ __git_tags ()
 
 __git_refs ()
 {
-	local cmd i is_hash=y dir="$(__gitdir "$1")"
+	local i is_hash=y dir="$(__gitdir "$1")"
+	local cur="${COMP_WORDS[COMP_CWORD]}" format refs
 	if [ -d "$dir" ]; then
-		if [ -e "$dir/HEAD" ]; then echo HEAD; fi
-		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
-			refs/tags refs/heads refs/remotes
+		case "$cur" in
+		refs*)
+			format="refname"
+			refs="${cur%/*}"
+			;;
+		*)
+			if [ -e "$dir/HEAD" ]; then echo HEAD; fi
+			format="refname:short"
+			refs="refs/tags refs/heads refs/remotes"
+			;;
+		esac
+		git --git-dir="$dir" for-each-ref --format="%($format)" \
+			$refs
 		return
 	fi
 	for i in $(git ls-remote "$dir" 2>/dev/null); do
-- 
1.6.0.4.814.gfe502

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

end of thread, other threads:[~2008-11-28  0:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-27 13:35 [PATCH] bash: complete full refs SZEDER Gábor
2008-11-27 21:29 ` Shawn O. Pearce
2008-11-28  0:46   ` SZEDER Gábor
2008-11-28  0:51     ` Shawn O. Pearce

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.