* [PATCH] completion: zsh: trivial improvement
@ 2021-06-08 2:38 Felipe Contreras
2021-06-08 5:01 ` SZEDER Gábor
0 siblings, 1 reply; 3+ messages in thread
From: Felipe Contreras @ 2021-06-08 2:38 UTC (permalink / raw)
To: git; +Cc: David Aguilar, Junio C Hamano, Felipe Contreras
$words has basically all the words we need, except the first one: git.
Lets simply add that instead of passing the original, which contains
options we don't want to pass downstream (like --git-dir).
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
contrib/completion/git-completion.zsh | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index cac6f61881..50f89145f3 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -219,9 +219,6 @@ __git_zsh_main ()
{
local curcontext="$curcontext" state state_descr line
typeset -A opt_args
- local -a orig_words
-
- orig_words=( ${words[@]} )
_arguments -C \
'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
@@ -261,7 +258,7 @@ __git_zsh_main ()
(( $+opt_args[--help] )) && command='help'
- words=( ${orig_words[@]} )
+ words=( git ${words[@]} )
__git_zsh_bash_func $command
;;
--
2.32.0.2.g41be0a4e50
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] completion: zsh: trivial improvement
2021-06-08 2:38 [PATCH] completion: zsh: trivial improvement Felipe Contreras
@ 2021-06-08 5:01 ` SZEDER Gábor
2021-06-08 5:37 ` Felipe Contreras
0 siblings, 1 reply; 3+ messages in thread
From: SZEDER Gábor @ 2021-06-08 5:01 UTC (permalink / raw)
To: Felipe Contreras; +Cc: git, David Aguilar, Junio C Hamano
On Mon, Jun 07, 2021 at 09:38:07PM -0500, Felipe Contreras wrote:
> $words has basically all the words we need, except the first one: git.
>
> Lets simply add that instead of passing the original, which contains
> options we don't want to pass downstream (like --git-dir).
In our Bash completion script $words contains all words of the current
command on the command line, including 'git -C tmp -c foo.bar=baz'.
Why should zsh completion behave differently?
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
> contrib/completion/git-completion.zsh | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
> index cac6f61881..50f89145f3 100644
> --- a/contrib/completion/git-completion.zsh
> +++ b/contrib/completion/git-completion.zsh
> @@ -219,9 +219,6 @@ __git_zsh_main ()
> {
> local curcontext="$curcontext" state state_descr line
> typeset -A opt_args
> - local -a orig_words
> -
> - orig_words=( ${words[@]} )
>
> _arguments -C \
> '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
> @@ -261,7 +258,7 @@ __git_zsh_main ()
>
> (( $+opt_args[--help] )) && command='help'
>
> - words=( ${orig_words[@]} )
> + words=( git ${words[@]} )
>
> __git_zsh_bash_func $command
> ;;
> --
> 2.32.0.2.g41be0a4e50
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] completion: zsh: trivial improvement
2021-06-08 5:01 ` SZEDER Gábor
@ 2021-06-08 5:37 ` Felipe Contreras
0 siblings, 0 replies; 3+ messages in thread
From: Felipe Contreras @ 2021-06-08 5:37 UTC (permalink / raw)
To: SZEDER Gábor, Felipe Contreras; +Cc: git, David Aguilar, Junio C Hamano
SZEDER Gábor wrote:
> On Mon, Jun 07, 2021 at 09:38:07PM -0500, Felipe Contreras wrote:
> > $words has basically all the words we need, except the first one: git.
> >
> > Lets simply add that instead of passing the original, which contains
> > options we don't want to pass downstream (like --git-dir).
>
> In our Bash completion script $words contains all words of the current
> command on the command line, including 'git -C tmp -c foo.bar=baz'.
>
> Why should zsh completion behave differently?
Because we use the _arguments function [1]. It changes the $words array
and removes all the arguments it was able to parse. All that remains is
that which it didn't understand.
If you do:
git --git-dir=x show --<tab>
_arguments will remove 'git --git-dir=x'. And there is no point in
passing '--git-dir=x' to _git_show. It provides no useful information,
and it was already processed by __git_zsh_main and __git_dir is set.
__git_main doesn't need to change $words, but it does increase
__git_cmd_idx to match the position of the command.
But since in the zsh case _argments already modified $words, we can just
add 'git' to the start and always use __git_cmd_idx=1.
[1] https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-Functions
--
Felipe Contreras
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-08 5:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 2:38 [PATCH] completion: zsh: trivial improvement Felipe Contreras
2021-06-08 5:01 ` SZEDER Gábor
2021-06-08 5:37 ` Felipe Contreras
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/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).