* [PATCH] completion: improve doc for complex aliases
@ 2023-09-09 15:49 Philippe Blain via GitGitGadget
2023-09-10 2:02 ` Eric Sunshine
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Philippe Blain via GitGitGadget @ 2023-09-09 15:49 UTC (permalink / raw)
To: git; +Cc: Steffen Prohaska, Philippe Blain, Philippe Blain
From: Philippe Blain <levraiphilippeblain@gmail.com>
The completion code can be told to use a particular completion for
aliases that shell out by using ': git <cmd> ;' as the first command of
the alias. This only works if <cmd> and the semicolon are separated by a
space. The examples have that space but it's not clear if it's just for
style or if it's mandatory.
Explicitely mention it.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
completion: improve doc for complex aliases
The completion code can be told to use a particular completion for
aliases that shell out by using ': git ;' as the first command of the
alias. This only works if and the semicolon are separated by a space.
The examples have that space but it's not clear if it's just for style
or if it's mandatory.
Explicitely mention it.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1585%2Fphil-blain%2Fcompletion-shell-aliases-doc-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1585/phil-blain/completion-shell-aliases-doc-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1585
contrib/completion/git-completion.bash | 1 +
1 file changed, 1 insertion(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dc95c34cc85..659df570496 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -28,6 +28,7 @@
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
+# Be sure to add a space between the command name and the ';'.
#
# If you have a command that is not part of git, but you would still
# like completion, you can use __git_complete:
base-commit: 23c56f7bd5f1667f8b793d796bf30e39545920f6
--
gitgitgadget
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] completion: improve doc for complex aliases
2023-09-09 15:49 [PATCH] completion: improve doc for complex aliases Philippe Blain via GitGitGadget
@ 2023-09-10 2:02 ` Eric Sunshine
2023-09-12 1:04 ` Linus Arver
2023-09-12 17:02 ` [PATCH v2] " Philippe Blain via GitGitGadget
2 siblings, 0 replies; 10+ messages in thread
From: Eric Sunshine @ 2023-09-10 2:02 UTC (permalink / raw)
To: Philippe Blain via GitGitGadget; +Cc: git, Steffen Prohaska, Philippe Blain
On Sat, Sep 9, 2023 at 12:25 PM Philippe Blain via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> The completion code can be told to use a particular completion for
> aliases that shell out by using ': git <cmd> ;' as the first command of
> the alias. This only works if <cmd> and the semicolon are separated by a
> space. The examples have that space but it's not clear if it's just for
> style or if it's mandatory.
>
> Explicitely mention it.
s/Explicitely/Explicitly/
> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] completion: improve doc for complex aliases
2023-09-09 15:49 [PATCH] completion: improve doc for complex aliases Philippe Blain via GitGitGadget
2023-09-10 2:02 ` Eric Sunshine
@ 2023-09-12 1:04 ` Linus Arver
2023-09-12 12:13 ` Philippe Blain
2023-09-12 17:02 ` [PATCH v2] " Philippe Blain via GitGitGadget
2 siblings, 1 reply; 10+ messages in thread
From: Linus Arver @ 2023-09-12 1:04 UTC (permalink / raw)
To: Philippe Blain via GitGitGadget, git; +Cc: Steffen Prohaska, Philippe Blain
Hi Philippe,
"Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> The completion code can be told to use a particular completion for
> aliases that shell out by using ': git <cmd> ;' as the first command of
> the alias. This only works if <cmd> and the semicolon are separated by a
> space. The examples have that space but it's not clear if it's just for
> style or if it's mandatory.
>
> Explicitely mention it.
It would be even more helpful if you explain _why_ it is mandatory in
the commit message. Is there some Bash-specific behavior or something
else going on here?
If you are unable to explain why, then as an alternative you could
explain the error or buggy behavior (any error messages encountered, for
example) you observe on your system when you do not use the space (which
is corrected by applying the suggestion you are adding in this patch).
Thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] completion: improve doc for complex aliases
2023-09-12 1:04 ` Linus Arver
@ 2023-09-12 12:13 ` Philippe Blain
0 siblings, 0 replies; 10+ messages in thread
From: Philippe Blain @ 2023-09-12 12:13 UTC (permalink / raw)
To: Linus Arver, Philippe Blain via GitGitGadget, git; +Cc: Steffen Prohaska
Hi Linus,
Le 2023-09-11 à 21:04, Linus Arver a écrit :
> Hi Philippe,
>
> "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Philippe Blain <levraiphilippeblain@gmail.com>
>>
>> The completion code can be told to use a particular completion for
>> aliases that shell out by using ': git <cmd> ;' as the first command of
>> the alias. This only works if <cmd> and the semicolon are separated by a
>> space. The examples have that space but it's not clear if it's just for
>> style or if it's mandatory.
>>
>> Explicitely mention it.
>
> It would be even more helpful if you explain _why_ it is mandatory in
> the commit message. Is there some Bash-specific behavior or something
> else going on here?
>
> If you are unable to explain why, then as an alternative you could
> explain the error or buggy behavior (any error messages encountered, for
> example) you observe on your system when you do not use the space (which
> is corrected by applying the suggestion you are adding in this patch).
Yeah, I guess I did not investigate why it did not work without the space,
it would be more complete if I did.
There's no error message though, it just does not work without the space
(as I wrote in the commit message) in the sense that it won't suggest completion
for the git command '<cmd>'.
I'll investigate and update the commit message.
Thanks,
Philippe.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] completion: improve doc for complex aliases
2023-09-09 15:49 [PATCH] completion: improve doc for complex aliases Philippe Blain via GitGitGadget
2023-09-10 2:02 ` Eric Sunshine
2023-09-12 1:04 ` Linus Arver
@ 2023-09-12 17:02 ` Philippe Blain via GitGitGadget
2023-09-13 0:58 ` Junio C Hamano
` (2 more replies)
2 siblings, 3 replies; 10+ messages in thread
From: Philippe Blain via GitGitGadget @ 2023-09-12 17:02 UTC (permalink / raw)
To: git
Cc: Steffen Prohaska, Eric Sunshine, Linus Arver, Philippe Blain,
Philippe Blain
From: Philippe Blain <levraiphilippeblain@gmail.com>
The completion code can be told to use a particular completion for
aliases that shell out by using ': git <cmd> ;' as the first command of
the alias. This only works if <cmd> and the semicolon are separated by a
space, since if the space is missing __git_aliased_command returns (for
example) 'checkout;' instead of just 'checkout', and then
__git_complete_command fails to find a completion for 'checkout;'.
The examples have that space but it's not clear if it's just for
style or if it's mandatory. Explicitly mention it.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
completion: improve doc for complex aliases
Changes since v1:
* fixed the typo pointed out by Eric
* added an explanation of why the space is mandatory, as suggested by
Linus
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1585%2Fphil-blain%2Fcompletion-shell-aliases-doc-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1585/phil-blain/completion-shell-aliases-doc-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1585
Range-diff vs v1:
1: b3621ed25f0 ! 1: 96a0867c5ad completion: improve doc for complex aliases
@@ Commit message
The completion code can be told to use a particular completion for
aliases that shell out by using ': git <cmd> ;' as the first command of
the alias. This only works if <cmd> and the semicolon are separated by a
- space. The examples have that space but it's not clear if it's just for
- style or if it's mandatory.
+ space, since if the space is missing __git_aliased_command returns (for
+ example) 'checkout;' instead of just 'checkout', and then
+ __git_complete_command fails to find a completion for 'checkout;'.
- Explicitely mention it.
+ The examples have that space but it's not clear if it's just for
+ style or if it's mandatory. Explicitly mention it.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
contrib/completion/git-completion.bash | 1 +
1 file changed, 1 insertion(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dc95c34cc85..659df570496 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -28,6 +28,7 @@
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
+# Be sure to add a space between the command name and the ';'.
#
# If you have a command that is not part of git, but you would still
# like completion, you can use __git_complete:
base-commit: 23c56f7bd5f1667f8b793d796bf30e39545920f6
--
gitgitgadget
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2] completion: improve doc for complex aliases
2023-09-12 17:02 ` [PATCH v2] " Philippe Blain via GitGitGadget
@ 2023-09-13 0:58 ` Junio C Hamano
2023-09-14 22:50 ` Linus Arver
2023-09-14 22:33 ` Linus Arver
2023-09-20 18:28 ` [PATCH] completion: loosen and document the requirement around completing alias Junio C Hamano
2 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2023-09-13 0:58 UTC (permalink / raw)
To: Philippe Blain via GitGitGadget
Cc: git, Steffen Prohaska, Eric Sunshine, Linus Arver, Philippe Blain
"Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> The completion code can be told to use a particular completion for
> aliases that shell out by using ': git <cmd> ;' as the first command of
> the alias. This only works if <cmd> and the semicolon are separated by a
> space, since if the space is missing __git_aliased_command returns (for
> example) 'checkout;' instead of just 'checkout', and then
> __git_complete_command fails to find a completion for 'checkout;'.
>
> The examples have that space but it's not clear if it's just for
> style or if it's mandatory. Explicitly mention it.
>
> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
> ---
Thanks. I scanned the case statement in the loop in the function
and thought "hmph, everybody says ': git <cmd> ;' but is 'git'
really needed?"
I had "git l3" alias that invokes "$HOM#/bin/git-l" command, like so:
[alias]
l3 = "!sh -c ': git log ; git l \"$@\"' -"
but if I did 's/: git log/: log/' it still completes just fine.
I wonder if this hack is worth adding, instead of (or in addition
to) requiring the user to insert $IFS to please the "parser", we can
honor the rather obvious wish of the user in a more direct way.
contrib/completion/git-completion.bash | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git c/contrib/completion/git-completion.bash w/contrib/completion/git-completion.bash
index 19139ac121..e31d71955f 100644
--- c/contrib/completion/git-completion.bash
+++ w/contrib/completion/git-completion.bash
@@ -1183,7 +1183,7 @@ __git_aliased_command ()
:) : skip null command ;;
\'*) : skip opening quote after sh -c ;;
*)
- cur="$word"
+ cur="${word%;}"
break
esac
done
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2] completion: improve doc for complex aliases
2023-09-12 17:02 ` [PATCH v2] " Philippe Blain via GitGitGadget
2023-09-13 0:58 ` Junio C Hamano
@ 2023-09-14 22:33 ` Linus Arver
2023-09-20 18:28 ` [PATCH] completion: loosen and document the requirement around completing alias Junio C Hamano
2 siblings, 0 replies; 10+ messages in thread
From: Linus Arver @ 2023-09-14 22:33 UTC (permalink / raw)
To: Philippe Blain via GitGitGadget, git
Cc: Steffen Prohaska, Eric Sunshine, Philippe Blain
"Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> The completion code can be told to use a particular completion for
> aliases that shell out by using ': git <cmd> ;' as the first command of
> the alias. This only works if <cmd> and the semicolon are separated by a
> space, since if the space is missing __git_aliased_command returns (for
> example) 'checkout;' instead of just 'checkout', and then
> __git_complete_command fails to find a completion for 'checkout;'.
>
> The examples have that space but it's not clear if it's just for
> style or if it's mandatory. Explicitly mention it.
>
> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
> ---
> completion: improve doc for complex aliases
>
> Changes since v1:
>
> * fixed the typo pointed out by Eric
> * added an explanation of why the space is mandatory, as suggested by
> Linus
>
Thanks for the investigation. The commit message reads much better now.
This LGTM, but I think Junio's review comments [1] are worth
considering. I'll respond there also.
[1] https://lore.kernel.org/git/xmqqo7i6khxv.fsf@gitster.g/#t
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] completion: improve doc for complex aliases
2023-09-13 0:58 ` Junio C Hamano
@ 2023-09-14 22:50 ` Linus Arver
0 siblings, 0 replies; 10+ messages in thread
From: Linus Arver @ 2023-09-14 22:50 UTC (permalink / raw)
To: Junio C Hamano, Philippe Blain via GitGitGadget
Cc: git, Steffen Prohaska, Eric Sunshine, Philippe Blain
Junio C Hamano <gitster@pobox.com> writes:
> "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Philippe Blain <levraiphilippeblain@gmail.com>
>>
>> The completion code can be told to use a particular completion for
>> aliases that shell out by using ': git <cmd> ;' as the first command of
>> the alias. This only works if <cmd> and the semicolon are separated by a
>> space, since if the space is missing __git_aliased_command returns (for
>> example) 'checkout;' instead of just 'checkout', and then
>> __git_complete_command fails to find a completion for 'checkout;'.
>>
>> The examples have that space but it's not clear if it's just for
>> style or if it's mandatory. Explicitly mention it.
>>
>> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
>> ---
>
> Thanks. I scanned the case statement in the loop in the function
> and thought "hmph, everybody says ': git <cmd> ;' but is 'git'
> really needed?"
>
> I had "git l3" alias that invokes "$HOM#/bin/git-l" command, like so:
>
> [alias]
> l3 = "!sh -c ': git log ; git l \"$@\"' -"
>
> but if I did 's/: git log/: log/' it still completes just fine.
Interesting! I searched for the 'git <cmd>' and got some hits in
"t9902-completion.sh" when running "git grep -nE 'git <cmd>'":
t/t9902-completion.sh:2432:test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
t/t9902-completion.sh:2441:test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
t/t9902-completion.sh:2450:test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
When I did 's/: git log/: log/' in the test at line 2450, the test still
passed. Perhaps we should add this "git"-less version as another test
case?
> I wonder if this hack is worth adding, instead of (or in addition
> to) requiring the user to insert $IFS to please the "parser", we can
> honor the rather obvious wish of the user in a more direct way.
>
>
>
> contrib/completion/git-completion.bash | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git c/contrib/completion/git-completion.bash w/contrib/completion/git-completion.bash
> index 19139ac121..e31d71955f 100644
> --- c/contrib/completion/git-completion.bash
> +++ w/contrib/completion/git-completion.bash
> @@ -1183,7 +1183,7 @@ __git_aliased_command ()
> :) : skip null command ;;
> \'*) : skip opening quote after sh -c ;;
> *)
> - cur="$word"
> + cur="${word%;}"
> break
> esac
> done
I think this is a good defensive technique. This obviously changes the
guidance that Phillipe gave in their patch (we no longer have to worry
about adding a space or not between "word" and ";", so there's no need
to mention this explicitly any more), but to me this seems like a better
experience for our users because it's one less thing they have to worry
about.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] completion: loosen and document the requirement around completing alias
2023-09-12 17:02 ` [PATCH v2] " Philippe Blain via GitGitGadget
2023-09-13 0:58 ` Junio C Hamano
2023-09-14 22:33 ` Linus Arver
@ 2023-09-20 18:28 ` Junio C Hamano
2023-09-20 18:46 ` Junio C Hamano
2 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2023-09-20 18:28 UTC (permalink / raw)
To: Philippe Blain; +Cc: git
Recently we started to tell users to spell ": git foo ;" with
space(s) around 'foo' for an alias to be completed similarly
to the 'git foo' command. It however is easy to also allow users to
spell it in a more natural way with the semicolon attached to 'foo',
i.e. ": git foo;". Also, add a comment to note that 'git' is optional
and writing ": foo;" would complete the alias just fine.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* We've discussed this when we reviewed the topic that just hit
'master'. Before we forget...
contrib/completion/git-completion.bash | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git c/contrib/completion/git-completion.bash w/contrib/completion/git-completion.bash
index 47fd664ea5..477ef8157a 100644
--- c/contrib/completion/git-completion.bash
+++ w/contrib/completion/git-completion.bash
@@ -28,7 +28,8 @@
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
-# Be sure to add a space between the command name and the ';'.
+# Note that "git" is optional --- '!f() { : commit; ...}; f' would complete
+# just like the 'git commit' command.
#
# If you have a command that is not part of git, but you would still
# like completion, you can use __git_complete:
@@ -1183,7 +1184,7 @@ __git_aliased_command ()
:) : skip null command ;;
\'*) : skip opening quote after sh -c ;;
*)
- cur="$word"
+ cur="${word%;}"
break
esac
done
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] completion: loosen and document the requirement around completing alias
2023-09-20 18:28 ` [PATCH] completion: loosen and document the requirement around completing alias Junio C Hamano
@ 2023-09-20 18:46 ` Junio C Hamano
0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2023-09-20 18:46 UTC (permalink / raw)
To: Philippe Blain; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
> * We've discussed this when we reviewed the topic that just hit
> 'master'. Before we forget...
>
> contrib/completion/git-completion.bash | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
And here is an obligatory "test" update I will squash into the main
patch. The new ones copy a canonical ": git <cmd> ; ..." test and
remove 'git' and also the space before the semicolon.
diff --git c/t/t9902-completion.sh w/t/t9902-completion.sh
index 47e20fb8b1..a7c3b4eb63 100755
--- c/t/t9902-completion.sh
+++ w/t/t9902-completion.sh
@@ -2464,6 +2464,24 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
EOF
'
+test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
+ test_config alias.co "!f() { : checkout ; if ... } f" &&
+ test_completion "git co m" <<-\EOF
+ main Z
+ mybranch Z
+ mytag Z
+ EOF
+'
+
+test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
+ test_config alias.co "!f() { : checkout; if ... } f" &&
+ test_completion "git co m" <<-\EOF
+ main Z
+ mybranch Z
+ mytag Z
+ EOF
+'
+
test_expect_success 'completion without explicit _git_xxx function' '
test_completion "git version --" <<-\EOF
--build-options Z
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-09-20 18:47 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-09 15:49 [PATCH] completion: improve doc for complex aliases Philippe Blain via GitGitGadget
2023-09-10 2:02 ` Eric Sunshine
2023-09-12 1:04 ` Linus Arver
2023-09-12 12:13 ` Philippe Blain
2023-09-12 17:02 ` [PATCH v2] " Philippe Blain via GitGitGadget
2023-09-13 0:58 ` Junio C Hamano
2023-09-14 22:50 ` Linus Arver
2023-09-14 22:33 ` Linus Arver
2023-09-20 18:28 ` [PATCH] completion: loosen and document the requirement around completing alias Junio C Hamano
2023-09-20 18:46 ` Junio C Hamano
Code repositories for project(s) associated with this public inbox
https://80x24.org/pub/scm/git/git.git/
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 read-only IMAP folder(s) and NNTP newsgroup(s).