Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: conditionally match part of file name to most recently modified file
- X-seq: zsh-users 11583
- From: Peter Stephenson <pws@xxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Re: conditionally match part of file name to most recently modified file
- Date: Mon, 18 Jun 2007 11:09:48 +0100
- In-reply-to: <20070617211644.GA11636@xxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <20070617211644.GA11636@xxxxxxxxxxxx>
On Sun, 17 Jun 2007 23:16:44 +0200
Eric Smith <es@xxxxxxxxxxxx> wrote:
> I want to be able to type
> "vim foo"
> in order to edit the last file whose name contains the string
> "foo".
> 
> I guess this might be achieved with compdef and compadd 
> with the *(om[1]).  
You could do it as a completion function, although the simple case
you've asked for can be done easily with an ordinary shell function:
vim() {
  # assume the file is the last argument
  if [[ ! -f $argv[-1] ]]; then
    argv[-1]=(*$argv[-1]*(om[1]))
  fi
  command vim "$@"
}
You can complete the most recent matching file using a generic completer:
  zstyle ':completion:most-recent-file:*' match-original both
  zstyle ':completion:most-recent-file::::' completer _menu _files _match
  zstyle ':completion:most-recent-file:*' file-sort modification
  zstyle ':completion:most-recent-file:*' file-patterns '*:all\ files'
  zstyle ':completion:most-recent-file:*' hidden all
  zle -C most-recent-file menu-complete _generic
  bindkey '^X.' most-recent-file
This is different from what you asked for in that you have to type a "*" at
the start yourself if you want to match a substring.
I had a look at writing a completion function that did exactly what you
wanted; must of it is simple but I got hopelessly stuck trying to persuade
the completion system not to sort the matches (the equivalent of the
file-sort style above).  That ought to be fixable.
-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
Messages sorted by:
Reverse Date,
Date,
Thread,
Author