From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30806 invoked from network); 24 Dec 2021 02:06:11 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Dec 2021 02:06:11 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1640311571; b=QK931EAOCLZPbX179ZQMAG/2arudr53LvjeRt1DqreqWJIZa5XSsZD1KIhd9MQsplKPobm5E4S VOnizKjjMFPMbTTmj7FdXgySPyDMvqSN7VZNA0/uTr77sbV2Nsg168+bOypkdOfb4bLsgLU8jJ r5xl8JHaZtOoilvkMv/swLf6GSgAVoWpdiXDypSC3g5Ocs+KXeY9soWN8CqvOGRPfFx/kDz0/3 4wwT34SzZdpCRHs+tt3cFDCnWW0d7DqbV+11CR+HsKpkol0Ld3kqsYr3Nbg+9gyQ6vum0YTCDm iXpb8IVbMECqrGj/UmFLEKlryg5MKDvbh84UwZx6cBFv7w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (pug.qqx.org) smtp.remote-ip=50.116.43.67; dkim=pass header.d=schrab.com header.s=mail header.a=rsa-sha256; dmarc=none header.from=schrab.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1640311571; bh=mAGzkmB9KWDVKxdXPSv7r9QWZ8bdedyXeu/wImDnL/I=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:To:From:DKIM-Signature:DKIM-Signature; b=mpycwD0eH7PcMWoDIWaW7tb8/kxdybrXqrTomXvTA/HhjDzmZDUf16snJIWkfXp9m+zl6uV+1i 1TuSXqlQvqyy/uJ7/f/QNFBrG2gBW98HDVQcTtk0hvrKD9njRXy5dbW8eKT3wfNLLo/AgylgBX wBi95Lizta4iwpAIVsfxBY36zkws6TA8mluucw/lghE6egcoi9vmOErc56FVTX2iu1HNS07iiB 6cJKelfW9kIB1kNZhBdQmvkHbIGcyLIn+UPkt2RdElhZDkPKD+IyWndrbFXXmv+bQp1QdVKMBa I7JJcFp/aQwAmHuRAv+w6p/vEVgZJ1L7aaKeCM+DdaZ6Aw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=GcZ/gsowVx3SVf7gOlMjKxzf2mkh7M+nZsVAYGS2kdw=; b=Q258X5U+og6M0V9Xkh/FrNlfL7 UM5IY0cZaBnp6U5AV+edBfMIiF2veZv5KxgQTHbrZH/iOKo8IRPDVAlK4llYvfW1HscKvWaxHA9k2 jIxGkubiZW33gRRTCsftyjEsPGGxlsEeYJRe1ZTECSDeAGSXYEM6970F+i9k7F8Zk5QuxzrtdutSC tjvLZ4AlLcyEStocQoNEMVqxaFaqYbycvgwIXPk3LWvahROKIT0pw3X8dI2ZZLVvFujZsem2ObOas 1fz0zvzGRvgpm6YeefFvKgODQOQj4PG0EAsv5e8bdfESl8dEEl1BmkI0cwAgKanxN4pbarqtcGVhU xf9behWw==; Received: from authenticated user by zero.zsh.org with local id 1n0ZyE-000Pnl-Bm; Fri, 24 Dec 2021 02:06:10 +0000 Authentication-Results: zsh.org; iprev=pass (pug.qqx.org) smtp.remote-ip=50.116.43.67; dkim=pass header.d=schrab.com header.s=mail header.a=rsa-sha256; dmarc=none header.from=schrab.com; arc=none Received: from pug.qqx.org ([50.116.43.67]:60178) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1n0Zxf-000PVY-JP; Fri, 24 Dec 2021 02:05:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=schrab.com; s=mail; t=1640311533; bh=mAGzkmB9KWDVKxdXPSv7r9QWZ8bdedyXeu/wImDnL/I=; h=From:To:Subject:Date:From; b=Zxaq8kG1GhSvPvF31lgaWPVSAuvNiHPSqfJPhU5tKffIktZOV/Pd4zvNyHNYJAS01 g8H6SjD3bE641YXF6YtqNqg1LH5xbf+4jieDM6GEX6VyqENOqwTw0GKeDSFeM7JBUL 1LgVMX3NtxwqVrm3/P2hPLGdZlVZ/k3ZyZfdigksjRtP/kHsrr00l/p28ovPEcElHs nGqBxNsvjGan24M/BuvKYrFbF8O4fJDHXg5OkyN+T3+klhs7RuQqAY4XOywFT5L3tu r8zhubaYrYXD5xxkkZPbbxHC4tF8Mh7c3BZ/vXJonlv6c9gGO5pXKKjAaGwYfzJ6oN s8zYGa+Z+PM/w== Received: by pug.qqx.org (Postfix, from userid 1000) id 06E231E122; Thu, 23 Dec 2021 21:05:33 -0500 (EST) From: Aaron Schrab To: zsh-workers@zsh.org Subject: [PATCH] _git: Use associative array for third-party completion Date: Thu, 23 Dec 2021 21:05:21 -0500 Message-Id: <20211224020521.28737-1-aaron@schrab.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 49664 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: 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