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

Re: Insert Most Recent File



On 17 September 2011 12:32, Bastien Dejean <eschyle@xxxxxxxxx> wrote:
> Hi,
>
> I noticed that the _most_recent_file widget doesn't necessarily return
> the most recent file (to me, it should be `ls -tc | head -1`).
>
> Is there a way to configure this widget to enforce the expected behavior?

-tc means ctime, which is the time the status of the file changed (ie
permissions and ownership), -t means mtime which is the last time the
actual contents of the file were changed. So I would expect something
that gets the recent file to use the mtime, which is what zsh does do
(ctime is always equal to or later than mtime though, afaik, unless
someone fiddled with the value manually). To answer your question
however, you can't configure the _most_recent_file widget to do this,
it has (om) written in it, it would have to be (oc) to use ctime.

I have this configuration which defines two widgets that complete
sorting on mtime and atime respectively,

zstyle ':completion:most-recent-file:*' match-original both
zstyle ':completion:most-recent-file:*' file-sort modification
zstyle ':completion:most-recent-file:*' file-patterns '*:all\ files'
zstyle ':completion:most-recent-file:*' hidden all
zstyle ':completion:most-recent-file:*' completer _files
zle -C most-recent-file menu-complete _generic

zstyle ':completion:most-accessed-file:*' match-original both
zstyle ':completion:most-accessed-file:*' file-sort access
zstyle ':completion:most-accessed-file:*' file-patterns '*:all\ files'
zstyle ':completion:most-accessed-file:*' hidden all
zstyle ':completion:most-accessed-file:*' completer _files
zle -C most-accessed-file menu-complete _generic

if you use 'change' or 'inode' for the file-sort style, it will use
ctime for sorting. Then you just need to bindkey '^whatever'
most-recent-file to use it.
-- 
Mikael Magnusson



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