From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3714 invoked by alias); 28 Feb 2014 21:15:02 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32445 Received: (qmail 26942 invoked from network); 28 Feb 2014 21:14:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=DByofsLKEDDXC1/lQIO4ltCWl4Am5ECgyAOHf8y1j8E=; b=aawX+NjLkOg8PAgwm0fBA9gxX1dgfFcLk9PBQzABAm2ju28MxowoHAQcPmhi4voa9d M/f6YTWcfC2MnlUKfq3kVPeNFCwZ0gb9154fdpw2sMn1cfQBz47yfogXhKLxJ9vS2yfn 1kx6cwc4Vyf86feGPZuy1pLwwpsAWFn+B5eCeaBYd06jkKpdstSrRUqCrbjeKOc49TDS UYthDvUBBe+Plu96PGfzw9znZYKLw5UcdNRR1L3z7TA6qb6pxGuOBV0Swl2ja4qo1Dox +AAL2bTVsQ1+dky4fyHfnEUWBQPzcsmGlgzNN7frQ5AQkQOcH8daIZAIBcpFbBaKzMMZ 1NYg== MIME-Version: 1.0 X-Received: by 10.224.54.10 with SMTP id o10mr6815741qag.9.1393622092974; Fri, 28 Feb 2014 13:14:52 -0800 (PST) In-Reply-To: <29011.1393594448@thecus.kiddle.eu> References: <29011.1393594448@thecus.kiddle.eu> Date: Fri, 28 Feb 2014 22:14:52 +0100 Message-ID: Subject: Re: completer for file extensions From: Mikael Magnusson To: Oliver Kiddle Cc: Zsh workers Content-Type: text/plain; charset=UTF-8 On 28 February 2014 14:34, Oliver Kiddle wrote: > This is a completer for filename extensions after *. (or ^*.). So, for > example, you might have: > % rm *. > .patch .pdf.gz .tar.gz .html .gz > > File extensions are usually short so this probably doesn't seem > particularly useful but it doesn't really interfere with anything else > and it is actually sometimes useful. I think I originally wrote this > with the idea of it being a simple example for the bash2zsh book but it > didn't get used there and in the form below, it isn't quite as simple as > it was. > > Directories before *. are handled, so /tmp/*. will complete extensions > of files in /tmp but something like a*. is not: wouldn't be hard but I'm > not sure it'd be useful. > > In the past I've always used this after _expand but I've attempted to > make it better handle exact matches so it can be used before _expand or > _match. Unfortunately, with compadd -O, you can't tell if any of the > matches were exact. > > Oliver > > diff --git a/Completion/Base/Completer/_extensions b/Completion/Base/Completer/_extensions > new file mode 100644 > index 0000000..2fcfe82 > --- /dev/null > +++ b/Completion/Base/Completer/_extensions > @@ -0,0 +1,32 @@ > +#autoload > + > +# This completer completes filename extensions when completing > +# after *. or ^*. It can be used anywhere in the completer list > +# but if used after _expand, patterns that already match a file > +# will be expanded before it is called. > + > +compset -P '(#b)([~$][^/]#/|)(*/|)(\^|)\*.' || return 1 > + > +local -aU files > +local -a expl suf mfiles > + > +files=( ${(e)~match[1]}${match[2]}*.* ) || return 1 > +eval set -A files '${(MSI:'{1-${#${(O)files//[^.]/}[1]}}':)files%%.[^/]##}' This - needs to be a .. or BRACE_CCL needs to be set locally. Even with this fix, the completer does nothing for me. I tried printing both $files and $mfiles and they contain more or less the correct list of extensions, but nothing shows up through the completion system. -- Mikael Magnusson