zsh-users
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Daniel <quite@hack.org>, "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: completer that first expands global aliases  (Re: dsf)
Date: Tue, 8 Jan 2013 13:06:27 +0000 (GMT)	[thread overview]
Message-ID: <1357650387.9070.YahooMailNeo@web171903.mail.ir2.yahoo.com> (raw)
In-Reply-To: <kcgpl3$dec$1@ger.gmane.org>

Daniel wrote:
> I have a nice little recent-files completer, see below.
> (found here: http://michael.stapelberg.de/Artikel/zsh_recent_completion )
> 
> What I would like to add to this, is for it to expand global aliases inline,
> before trying to complete (and thus ending up completing files in my aliased
> directory).
> 
> I started trying to meld _generic and _expand_alias, but with my lack of
> fluency in zsh, I just made a mess :) Any help out there? Is there perhaps some

> zstyle ':completion:newest-files:*' completer _files

You can insert _expand_alias before _files in the list of completer
functions. I'm not sure if that works in the way you want: a global
alias will simply be expanded. If you tried that and it didn't work then
I would suspect that your default completer style is getting precedence
over this one. Try using more colons instead of a *:

zstyle ':completion:newest-files::::' completer _expand_alias _files

If this doesn't behave in the way you would like, perhaps give us some
examples of your global aliases and what you behaviour you would like.

> zstyle ':completion:newest-files:*' file-patterns '*~.*(omN[1,12])'
> zstyle ':completion:newest-files:*' menu select yes
> zstyle ':completion:newest-files:*' sort false
> zstyle ':completion:newest-files:*' matcher-list 'b:=*' # important

I do this in a somewhat different way. The comment on the last line
isn't particularly helpful. It makes matching use substrings so for
example typing
  ls pdf<Ctrl-X>r
will match *pdf* in order of file modification. Note that matching is
done after the globbing so if you have more than 12 newer files than any
of the matching ones, you won't get anything.

I use _match instead so if I want the most recent PDF file, I complete
after *.pdf. I also need the match-original style set for that to work.

I can't think of a different way to limit the number of matches to 12. I
simply turn off completion listing for the widget and it is rare that I
need to cycle through more than a couple of matches. This also has the
advantage that you can invoke reverse-menu-complete to get the oldest
file (which is sometimes useful).

I use the following:
  zstyle ':completion:most-recent-*::::' completer _menu _files _match
  zstyle ':completion:most-recent-*:*' file-sort modification
  zstyle ':completion:most-recent-*:*' hidden all
  zstyle ':completion:(match-word|most-recent-*):*' match-original both
  zstyle ':completion:most-recent-file:*' file-patterns '*(.):normal\ files'
  zstyle ':completion:most-recent-dir:*' file-patterns '*(/):directories'
  bindkey '^Xm' most-recent-file
  bindkey '^XM' most-recent-dir
  zle -C most-recent-file menu-complete _generic
  zle -C most-recent-dir menu-complete _generic

Note that I have a separate widget for directories. You may also want to
experiment with using _complete instead of _files to make it more
intelligent, at least in theory:
  zstyle ':completion:most-recent-*::::' completer _menu _complete _match
  zstyle ':completion:most-recent-file:*' file-patterns '%p(N):globbed-files'

Oliver



  parent reply	other threads:[~2013-01-08 13:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-07 10:01 dsf Daniel
2013-01-08  9:41 ` completer that first expands global aliases (Re: dsf) Daniel
2013-01-08  9:58   ` Peter Stephenson
2013-01-08 13:06   ` Oliver Kiddle [this message]
2013-01-08 17:01     ` Daniel
2013-01-08 18:24       ` Bart Schaefer
2013-01-08 21:29         ` Daniel
2013-01-09  4:40           ` Bart Schaefer
2013-01-09  7:29             ` Daniel
2013-01-09 16:05               ` Bart Schaefer

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=1357650387.9070.YahooMailNeo@web171903.mail.ir2.yahoo.com \
    --to=okiddle@yahoo.co.uk \
    --cc=quite@hack.org \
    --cc=zsh-users@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).