From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18066 invoked by alias); 28 Sep 2010 04:07:03 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15433 Received: (qmail 25943 invoked from network); 28 Sep 2010 04:07:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Tue, 28 Sep 2010 00:06:32 -0400 (EDT) From: "Benjamin R. Haskell" To: Conrad Irwin cc: zsh-users@zsh.org Subject: Re: _git Completion and custom commands In-Reply-To: Message-ID: References: User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-1463810530-621526883-1285646816=:30023" ---1463810530-621526883-1285646816=:30023 Content-Type: TEXT/PLAIN; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT On Tue, 28 Sep 2010, Conrad Irwin wrote: > Hi Zsh, > > I finally got round to trying out zsh today, and wow is it cool — I > don't believe I've been stuck on bash for all this time :). > > The one issue I've found is that the _git completion function (as of > 4.3.10 shipped with Debian testing) does not include custom commands > (though it does include aliases). > > (For those of you unfamiliar with git, any executable in your path > with a name like git-* can be called as git * with no hyphen) > > My question is then: how would I add my custom commands' names to the > list already completed by _git (without completely overriding or > modifying the system-wide configuration)? This has bothered me for a while, too. I think _git should include these by default. But, it's pretty easy to add: zstyle ':completion:*:git:*' user-commands ${${(k)commands[(I)git-*]}#git-} (I've found _git to be very about what it allows you to override via zstyles) Explanation of the '${${(k)commands[(I)git-*]}#git-}' portion: $commands is a built-in associative array that maps basenames to their full paths. E.g. one of my custom git- commands that it picks up is: commands[git-build-zsh]=/home/bhaskell/bin/git-build-zsh So, we're looking for the keys '(k)'. And we only want entries in the hash that have (I)ndexes matching 'git-*'. Then we want to remove the leading 'git-' portion ( ${...#git-} ). -- Best, Ben P.S. Played around a bit with (k), and [(MIRK)*], but couldn't seem to find a way to not repeat the 'git-' pattern. I'm sure a veteran could do it effortlessly. P.P.S. I found it a bit odd that: print -l ${( completes glob qualifiers rather than parameter expansion flags. ---1463810530-621526883-1285646816=:30023--