Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: completer that first expands global aliases (Re: dsf)



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




Messages sorted by: Reverse Date, Date, Thread, Author