zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Oliver Kiddle <okiddle@yahoo.co.uk>
Cc: Zsh workers <zsh-workers@zsh.org>
Subject: Re: completer for file extensions
Date: Fri, 28 Feb 2014 22:14:52 +0100	[thread overview]
Message-ID: <CAHYJk3RRtyS2uMGc1TG7DwYMQcF1KcpObiDOp3BeBidfBZ_9rw@mail.gmail.com> (raw)
In-Reply-To: <29011.1393594448@thecus.kiddle.eu>

On 28 February 2014 14:34, Oliver Kiddle <okiddle@yahoo.co.uk> 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


  reply	other threads:[~2014-02-28 21:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-28 13:34 Oliver Kiddle
2014-02-28 21:14 ` Mikael Magnusson [this message]
2014-02-28 22:08   ` Oliver Kiddle
2014-03-01 22:54     ` Mikael Magnusson
2014-03-03 15:33       ` Oliver Kiddle

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=CAHYJk3RRtyS2uMGc1TG7DwYMQcF1KcpObiDOp3BeBidfBZ_9rw@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=okiddle@yahoo.co.uk \
    --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).