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

Re: another (hopefully simple) completion question



William Scott wrote:
> Is there a simple way to complete with the sort order governed by  
> most recently touched file first (the order ls -t produces) rather  
> than the conventional order?  Ideally I'd like to bind it to ctl-tab  
> or some such key combo and retain the normal completion option with tab.

Yes, you can do this very flexibly just using styles.  The following is
the solution explained by Oliver in From Bash to Z Shell (Apress, ISBN
1-59059-376-6), page 407.  The _generic widget is really just a hook so
you can hang a special name on it, using styles to make it do something
different from normal completion.

# Use menu completion to cycle through files.
zle -C most-recent-file menu-complete _generic
# Use file completion, but add the _match completer so
# glob patterns can be used.
zstyle 'completion:most-recent-file::::' completer _menu _files _match
# Use the file-sort style to sort in modification time order.
zstyle ':completion:most-recent-file:*' file-sort modification
# We don't want to see the list of matches, just the results.
zstyle ':completion:most-recent-file:*' hidden all
# Optionally, restrict matches to regular files
zstyle ':completion:most-recent-file:*' file-patterns '*(.):normal\ files'
# Bind the widget.
bindkey '^X.' most-recent-file

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page still at http://www.pwstephenson.fsnet.co.uk/



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