{"thread":{"id":"55878","subject":"[PATCH] completion: zsh: trivial improvement","startedAt":"2021-06-08T02:38:34Z","lastAt":"2021-06-08T05:37:41Z","messageCount":3,"participants":["Felipe Contreras","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"426692","messageId":"20210608023807.907883-1-felipe.contreras@gmail.com","threadId":"55878","inReplyTo":null,"subject":"[PATCH] completion: zsh: trivial improvement","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-08T02:38:07Z","receivedAt":"2021-06-08T02:38:34Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"$words has basically all the words we need, except the first one: git.\n\nLets simply add that instead of passing the original, which contains\noptions we don't want to pass downstream (like --git-dir).\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex cac6f61881..50f89145f3 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -219,9 +219,6 @@ __git_zsh_main ()\n {\n \tlocal curcontext=\"$curcontext\" state state_descr line\n \ttypeset -A opt_args\n-\tlocal -a orig_words\n-\n-\torig_words=( ${words[@]} )\n \n \t_arguments -C \\\n \t\t'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \\\n@@ -261,7 +258,7 @@ __git_zsh_main ()\n \n \t\t(( $+opt_args[--help] )) && command='help'\n \n-\t\twords=( ${orig_words[@]} )\n+\t\twords=( git ${words[@]} )\n \n \t\t__git_zsh_bash_func $command\n \t\t;;\n-- \n2.32.0.2.g41be0a4e50\n\n"},{"id":"426699","messageId":"20210608050115.GC6312@szeder.dev","threadId":"55878","inReplyTo":"20210608023807.907883-1-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: zsh: trivial improvement","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-06-08T05:01:15Z","receivedAt":"2021-06-08T05:02:35Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, Jun 07, 2021 at 09:38:07PM -0500, Felipe Contreras wrote:\n> $words has basically all the words we need, except the first one: git.\n> \n> Lets simply add that instead of passing the original, which contains\n> options we don't want to pass downstream (like --git-dir).\n\nIn our Bash completion script $words contains all words of the current\ncommand on the command line, including 'git -C tmp -c foo.bar=baz'.\n\nWhy should zsh completion behave differently?\n\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  contrib/completion/git-completion.zsh | 5 +----\n>  1 file changed, 1 insertion(+), 4 deletions(-)\n> \n> diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\n> index cac6f61881..50f89145f3 100644\n> --- a/contrib/completion/git-completion.zsh\n> +++ b/contrib/completion/git-completion.zsh\n> @@ -219,9 +219,6 @@ __git_zsh_main ()\n>  {\n>  \tlocal curcontext=\"$curcontext\" state state_descr line\n>  \ttypeset -A opt_args\n> -\tlocal -a orig_words\n> -\n> -\torig_words=( ${words[@]} )\n>  \n>  \t_arguments -C \\\n>  \t\t'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \\\n> @@ -261,7 +258,7 @@ __git_zsh_main ()\n>  \n>  \t\t(( $+opt_args[--help] )) && command='help'\n>  \n> -\t\twords=( ${orig_words[@]} )\n> +\t\twords=( git ${words[@]} )\n>  \n>  \t\t__git_zsh_bash_func $command\n>  \t\t;;\n> -- \n> 2.32.0.2.g41be0a4e50\n> \n"},{"id":"426703","messageId":"60bf0217e0a90_198bd720828@natae.notmuch","threadId":"55878","inReplyTo":"20210608050115.GC6312@szeder.dev","subject":"Re: [PATCH] completion: zsh: trivial improvement","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-08T05:37:27Z","receivedAt":"2021-06-08T05:37:41Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"SZEDER Gábor wrote:\n> On Mon, Jun 07, 2021 at 09:38:07PM -0500, Felipe Contreras wrote:\n> > $words has basically all the words we need, except the first one: git.\n> > \n> > Lets simply add that instead of passing the original, which contains\n> > options we don't want to pass downstream (like --git-dir).\n> \n> In our Bash completion script $words contains all words of the current\n> command on the command line, including 'git -C tmp -c foo.bar=baz'.\n> \n> Why should zsh completion behave differently?\n\nBecause we use the _arguments function [1]. It changes the $words array\nand removes all the arguments it was able to parse. All that remains is\nthat which it didn't understand.\n\nIf you do:\n\n  git --git-dir=x show --<tab>\n\n_arguments will remove 'git --git-dir=x'. And there is no point in\npassing '--git-dir=x' to _git_show. It provides no useful information,\nand it was already processed by __git_zsh_main and __git_dir is set.\n\n__git_main doesn't need to change $words, but it does increase\n__git_cmd_idx to match the position of the command.\n\nBut since in the zsh case _argments already modified $words, we can just\nadd 'git' to the start and always use __git_cmd_idx=1.\n\n[1] https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-Functions\n\n-- \nFelipe Contreras"}]}