git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bash completion of "addable" files for `git add`
@ 2012-11-09 13:22 Andreas Zeidler
  2012-11-09 16:27 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Zeidler @ 2012-11-09 13:22 UTC (permalink / raw)
  To: git; +Cc: gitster

hi,

i've always been annoyed by having to type — or copy & paste — paths when i wanted to simply add some files to the index.  i know about the `add -i` interface, and that improves things a little, but having bash completion for so many other things it still seemed to much hassle.

so here's a patch adding bash completion on `git add` for modified, updated and untracked files.  i've also set up a pull request — before i found `Documentation/SubmittingPatches`.  fwiw, it's at https://github.com/git/git/pull/29

best regards,


andi


From cbac6caee7e788569562cb7138eb698cc46a1b8f Mon Sep 17 00:00:00 2001
From: Andreas Zeidler <az@zitc.de>
Date: Fri, 9 Nov 2012 13:05:43 +0100
Subject: [PATCH] add bash completion for "addable" files

this adds support for completing only modified, updated and untracked
files on `git add`, since almost always these are what you want to add
to the index.

the list of possible completions is determined using `git status` and
filtered using `egrep` and `sed`.

Signed-off-by: Andreas Zeidler <az@zitc.de>
---
 contrib/completion/git-completion.bash | 15 +++++++++++++++
 t/t9902-completion.sh                  | 11 +++++++++++
 2 files changed, 26 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index be800e0..4aa0981 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -799,6 +799,16 @@ _git_apply ()
 	COMPREPLY=()
 }
 
+__git_addable ()
+{
+	local dir="$(__gitdir)"
+	if [ -d "$dir" ]; then
+		git --git-dir="$dir" status --short --untracked=all |\
+			egrep '^.[UM?] ' | sed 's/^.. //'
+		return
+	fi
+}
+
 _git_add ()
 {
 	__git_has_doubledash && return
@@ -810,6 +820,11 @@ _git_add ()
 			--ignore-errors --intent-to-add
 			"
 		return
+		;;
+	*)
+		__gitcomp "$(__git_addable)"
+		return
+		;;
 	esac
 	COMPREPLY=()
 }
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index cbd0fb6..a7c81d3 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -288,4 +288,15 @@ test_expect_failure 'complete tree filename with metacharacters' '
 	EOF
 '
 
+test_expect_success 'add completes untracked and modified names' '
+	echo other content >file1 &&
+	echo content >file2 &&
+	echo more >file3 &&
+	git add file1 &&
+	test_completion_long "git add f" <<-\EOF
+	file2_
+	file3_
+	EOF
+'
+
 test_done
-- 
1.8.0.1.g43af610


-- 
pgp key at http://zitc.de/pgp - http://wwwkeys.de.pgp.net/
upgrade to plone 4! -- http://plone.org/4

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

end of thread, other threads:[~2012-11-09 16:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-09 13:22 bash completion of "addable" files for `git add` Andreas Zeidler
2012-11-09 16:27 ` Jeff King

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).