git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: use native ZSH array pattern matching

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
May 26, 2020, 23:58 UTC
Message-ID
<20200526235834.GG1915090@camp.crustytoothpaste.net>
In-Reply-To
<pull.645.git.1590520398132.gitgitgadget@gmail.com>
On 2020-05-26 at 19:13:17, Marco Trevisan via GitGitGadget wrote:
Show 40 quoted lines
> From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
> 
> When clearing the builtin operations on re-sourcing in the ZSH case we
> can use the native ${parameters} associative array keys values to get
> the currently `__gitcomp_builtin_*` operations using pattern matching
> instead of using sed.
> 
> As also stated in commit 94408dc7, introducing this change the usage of
> sed has some overhead implications, while ZSH can do this check just
> using its native syntax.
> 
> Signed-off-by: Marco Trevisan (Treviño) <mail@3v1n0.net>
> ---
>     completion: Use native ZSH array pattern matching
>     
>     When clearing the builtin operations on re-sourcing in the ZSH case we
>     can use the native ${parameters} associative array keys values to get
>     the currently __gitcomp_builtin_* operations using pattern matching
>     instead of using sed.
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-645%2F3v1n0%2Fzsh-native-operation-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-645/3v1n0/zsh-native-operation-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/645
> 
>  contrib/completion/git-completion.bash | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 70ad04e1b2a..ad6934a3864 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -373,7 +373,7 @@ __gitcomp ()
>  # Clear the variables caching builtins' options when (re-)sourcing
>  # the completion script.
>  if [[ -n ${ZSH_VERSION-} ]]; then
> -	unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
> +	unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
>  else
>  	unset $(compgen -v __gitcomp_builtin_)
>  fi

This file is necessarily used by both bash and zsh. Does bash (including the bash 3 used on macOS) happen to continue to work with this syntax?

We've had cases in the past where despite some code running under shell A, shell B, which also parsed file, choked on the data because it had to parse it even though it didn't execute it.

If so, and this works there, can you mention that in your commit message for future readers?

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Marco Trevisan via GitGitGadgetNext: Carlo Marcelo Arenas Belón
Message 2 of 8 in “completion: use native ZSH array pattern matching”
  1. completion: use native ZSH array pattern matchingMarco Trevisan via GitGitGadget, May 26, 2020
  2. brian m. carlsonMay 26, 2020
  3. Carlo Marcelo Arenas BelónMay 27, 2020
  4. brian m. carlsonMay 28, 2020
  5. Junio C HamanoMay 28, 2020
  6. brian m. carlsonMay 28, 2020
  7. Junio C HamanoMay 28, 2020
  8. Junio C HamanoMay 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.