From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Junio C Hamano <gitster@pobox.com>,
Eric Sunshine <sunshine@sunshineco.com>
Cc: git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PoC PATCH] completion: support 'git worktree'
Date: Fri, 21 Aug 2015 22:50:56 +0200 [thread overview]
Message-ID: <1440190256-21794-1-git-send-email-szeder@ira.uka.de> (raw)
In-Reply-To: <20150821224918.Horde.edB9u314lsP17FLUzwFsQA1@webmail.informatik.kit.edu>
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
> I wrote a completion function for 'git worktree' as well, turns out a week
> or two before you posted this, but I never submitted it as it was way too
> convoluted. Anyway, will send it in reply to this, just for reference.
And here it is.
From the number of indentation levels and comment lines you can see why
I haven't submitted this patch yet :)
OTOH it offers refs for -b and -B, and there are only fairly narrow
corner cases when 'git --options' can fool it (but that's a general
issue with __git_find_on_cmdline(), I wouldn't go into that).
contrib/completion/git-completion.bash | 59 ++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c97c648d7e..20a17e2c50 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2564,6 +2564,65 @@ _git_whatchanged ()
_git_log
}
+_git_worktree ()
+{
+ local subcommand subcommand_idx sc c=1
+ local subcommands="add prune"
+
+ while [ $c -lt $cword ] && [ -z "$subcommand" ]; do
+ for sc in $subcommands; do
+ if [ "$sc" = "${words[c]}" ]; then
+ subcommand=$sc
+ subcommand_idx=$c
+ break
+ fi
+ done
+ ((c++))
+ done
+
+ case "$subcommand,$cur" in
+ ,*)
+ __gitcomp "$subcommands"
+ ;;
+ add,--*)
+ __gitcomp "--detach"
+ ;;
+ add,*)
+ case "$prev" in
+ -b|-B)
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ -*) # $prev is an option without argument: have to complete
+ # the path for the new worktree, fall back to bash
+ # filename completion
+ ;;
+ *) # $prev is not an option, so it must be either the
+ # 'add' subcommand, an argument of an option (e.g.
+ # branch for -b|-B), or the path for the new worktree
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
+ # right after the 'add' subcommand, have to
+ # complete the path
+ :
+ else
+ case "${words[cword-2]}" in
+ -b|-B) # after '-b <branch>', have to complete
+ # the path
+ ;;
+ *) # after the path, have to complete the
+ # branch to be checked out
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ esac
+ fi
+ ;;
+ esac
+ ;;
+ prune,--*)
+ __gitcomp "--dry-run --verbose --expire"
+ ;;
+ esac
+}
+
__git_main ()
{
local i c=1 command __git_dir
--
2.5.0.418.gdd37a9b
next prev parent reply other threads:[~2015-08-21 20:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 20:49 [RFC/PATCH] contrib: teach completion about git-worktree options and arguments Eric Sunshine
2015-08-06 16:29 ` Eric Sunshine
2015-08-21 17:21 ` Junio C Hamano
2015-08-21 20:49 ` SZEDER Gábor
2015-08-21 20:50 ` SZEDER Gábor [this message]
2015-08-21 21:59 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440190256-21794-1-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).