Thread (2 messages) 2 messages, 1 author, 2016-06-15

[RFC/PATCH] contrib: teach completion about git-worktree options and arguments

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:05:52
Subsystem: the rest · Maintainer: Linus Torvalds

Complete subcommands 'add' and 'prune', as well as their respective
options --force, --detach, --dry-run, --verbose, and --expire. Also
complete 'refname' in "git worktree add [-b <newbranch>] <path>
<refname>".

Signed-off-by: Eric Sunshine <redacted>
---

This is RFC since this is my first foray into the Git completion script,
and there are likely better and more idiomatic ways to accomplish this.

 contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c97c648..07c34ef 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2564,6 +2564,38 @@ _git_whatchanged ()
 	_git_log
 }
 
+_git_worktree ()
+{
+	local subcommands='add prune'
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+	local c=2 n=0 refpos=2
+	if [ -z "$subcommand" ]; then
+		__gitcomp "$subcommands"
+	else
+		case "$subcommand,$cur" in
+		add,--*)
+			__gitcomp "--force --detach"
+			;;
+		add,*)
+			while [ $c -lt $cword ]; do
+				case "${words[c]}" in
+				--*) ;;
+				-[bB]) ((refpos++)) ;;
+				*) ((n++)) ;;
+				esac
+				((c++))
+			done
+			if [ $n -eq $refpos ]; then
+				__gitcomp_nl "$(__git_refs)"
+			fi
+			;;
+		prune,--*)
+			__gitcomp "--dry-run --verbose --expire"
+			;;
+		esac
+	fi
+}
+
 __git_main ()
 {
 	local i c=1 command __git_dir
-- 
2.5.0.rc3.407.g68aafd0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help