From: Steffen Prohaska <prohaska@zib.de>
To: git@vger.kernel.org
Cc: Steffen Prohaska <prohaska@zib.de>
Subject: [PATCH] completion: Handle '!f() { ... }; f' aliases
Date: Sat, 7 Jun 2014 16:10:21 +0200 [thread overview]
Message-ID: <1402150221-25548-1-git-send-email-prohaska@zib.de> (raw)
'!f() { ... }; f' is a recommended pattern to declare more complex
aliases (see git wiki [1]). This commit teaches the completion to
handle them.
When determining which completion to use for an alias, the opening brace
is now ignored in order to continue the search for a git command inside
the function body. For example, the alias '!f() { git commit ... }' now
triggers commit completion. Previously, the search stopped on '{', and
the completion tried it to determine how to complete, which obviously
was useless.
Furthermore, the null command ':' is now skipped, so that it can be used
as a workaround to declare the desired completion style. For example,
the alias '!f() { : git commit ; if ... ' now triggers commit
completion.
[1] https://git.wiki.kernel.org/index.php/Aliases
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
contrib/completion/git-completion.bash | 7 +++++++
t/t9902-completion.sh | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 2c59a76..aecb975 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -21,6 +21,11 @@
# source ~/.git-completion.sh
# 3) Consider changing your PS1 to also show the current branch,
# see git-prompt.sh for details.
+#
+# If you use complex aliases of form '!f() { ... }; f', you can use the null
+# command ':' as the first command in the function body to declare the desired
+# completion style. For example '!f() { : git commit ; ... }; f' will
+# tell the completion to use commit completion.
case "$COMP_WORDBREAKS" in
*:*) : great ;;
@@ -781,6 +786,8 @@ __git_aliased_command ()
-*) : option ;;
*=*) : setting env ;;
git) : git itself ;;
+ {) : skip start of shell helper function ;;
+ :) : skip null command ;;
*)
echo "$word"
return
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 2d4beb5..ea48681 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -550,6 +550,26 @@ test_expect_success 'complete files' '
test_completion "git add mom" "momified"
'
+test_expect_success 'completion uses <cmd> completion for alias !f() { VAR=val git <cmd> ... }' '
+ git config alias.co "!f() { VAR=val git checkout ... ; } f" &&
+ test_completion "git co m" <<-\EOF &&
+ master Z
+ mybranch Z
+ mytag Z
+ EOF
+ git config --unset alias.co
+'
+
+test_expect_success 'completion used <cmd> completion for alias !f() { : git <cmd> ; ... }' '
+ git config alias.co "!f() { : git checkout ; if ... } f" &&
+ test_completion "git co m" <<-\EOF &&
+ master Z
+ mybranch Z
+ mytag Z
+ EOF
+ git config --unset alias.co
+'
+
test_expect_failure 'complete with tilde expansion' '
git init tmp && cd tmp &&
test_when_finished "cd .. && rm -rf tmp" &&
--
2.0.0.244.g4e8e734
next reply other threads:[~2014-06-07 15:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-07 14:10 Steffen Prohaska [this message]
2014-06-08 9:02 ` [PATCH] completion: Handle '!f() { ... }; f' aliases Eric Sunshine
2014-06-09 12:54 ` [PATCH v2] " Steffen Prohaska
2014-06-10 5:27 ` Junio C Hamano
2014-06-12 18:41 ` Steffen Prohaska
2014-06-12 18:49 ` [PATCH v2] completion: Handle '!f() { ... }; f' and "!sh -c '...'" aliases Steffen Prohaska
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=1402150221-25548-1-git-send-email-prohaska@zib.de \
--to=prohaska@zib.de \
--cc=git@vger.kernel.org \
/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).