From: Aaron Schrab <aaron@schrab.com>
To: zsh-workers@zsh.org
Subject: [PATCH] _git: Use associative array for third-party completion
Date: Thu, 23 Dec 2021 21:05:21 -0500 [thread overview]
Message-ID: <20211224020521.28737-1-aaron@schrab.com> (raw)
When loading completion for third-party git commands use an associative
array to track if something has been loaded rather than a normal array.
I started looking into this after I added a `_git-f` file to my function
path while having `$f` defined as a variable I started getting `bad math
expression: operand expected` the first time I used git completion. The
line number referenced by that error pointed at where this was
apparently trying to see if there was already an entry in
`$_git_third_party_commands`. Unless I'm completely missing something
that wouldn't work as it was written. Since this section of the code is
trying to keep track of command names and an associated description an
associative array seems like a much better option. When later copying
this into `$third_party_commands` I've left that as a normal array.
---
Completion/Unix/Command/_git | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 04b5677ce..cecb80ac3 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -6267,8 +6267,8 @@ _git_commands () {
zstyle -a :completion:$curcontext: user-commands user_commands
local command
- for command in $_git_third_party_commands; do
- (( $+commands[git-${command%%:*}] )) && third_party_commands+=$command
+ for command in ${(k)_git_third_party_commands}; do
+ (( $+commands[git-${command}] )) && third_party_commands+=$command$_git_third_party_commands[$command]
done
local -a aliases
@@ -8475,7 +8475,7 @@ _git() {
}
# Load any _git-* definitions so that they may be completed as commands.
-declare -gUa _git_third_party_commands
+declare -gA _git_third_party_commands
_git_third_party_commands=()
local file input
@@ -8497,7 +8497,7 @@ for file in ${^fpath}/_git-*~(*~|*.zwc)(-.N); do
(( i++ ))
done < $file
- _git_third_party_commands+=$name$desc
+ _git_third_party_commands+=([$name]=$desc)
done
_git
--
2.33.0.464.g1972c5931b
reply other threads:[~2021-12-24 2:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20211224020521.28737-1-aaron@schrab.com \
--to=aaron@schrab.com \
--cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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).