Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: completer for file extensions
- X-seq: zsh-workers 32445
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- Subject: Re: completer for file extensions
- Date: Fri, 28 Feb 2014 22:14:52 +0100
- Cc: Zsh workers <zsh-workers@xxxxxxx>
- 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==
- In-reply-to: <29011.1393594448@thecus.kiddle.eu>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <29011.1393594448@thecus.kiddle.eu>
On 28 February 2014 14:34, Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> This is a completer for filename extensions after *. (or ^*.). So, for
> example, you might have:
> % rm *.<tab>
> .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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author