'zsh : listing and suggestions

The first command applied is "l" which corresponds to the alias:

alias l='grc -es --colour=auto ls --color -Gh -C -lrt'
  1. Once I type "l", I want, when I touch the TAB (auto)-completion , the most recent modified files as suggestions near to the prompt from which I perform the "l" + TAB completion..

As an example, here the below figure when typing a simple "l" command (seee alias above) :

example of alias "l" alias

Main goal : the most important goal of this post : if I type "l+TAB+TAB", I would like that the most recent file/directory appears firstly as suggestion : in my case, the first suggestion after this commmand would be filename2, after a second "TAB" the suggestion dir_1 and the third suggestion dir_8, etc (see the order of simple command "l").

  1. Now, if I type "l+TAB", I get :

example of typing "l+TAB"

In option,I would like to avoid this last result (under the form of a menu but I would like rather a list) when I perform a "l+TAB" but I don't know which line to add or modify in ~/.zshrc. This is not the priority.

UPDATE 1: I have almost found the solution for typing twice on TAB key after a "l" alias which can be assimilated to a ls -lrt. Here the peudo magic command :

bindkey '\t' reverse-menu-complete

But the problem is that with this option, when I press on a first time on TAB, a suggestion is automatically done with the most recent file or dir.

Example : I if do : $ l +TAB, I get on my following above capture :

early suggestion

What I would like to get is to have the most recent file suggestion when I type a second time on TAB and not as soon as I have typed a second time. I hope you understand my request. Tell me if this is not clear.

UPDATE 2: I am close the final wanted behavior. I set :

zstyle ':completion:*:complete:(ls|cd|cp|mv|vim|cat|more|tail|head|open):*' file-sort date reverse

bindkey '^\t' reverse-menu-complete
bindkey '^[[Z' menu-complete

If I do a first l + TAB, I have the correct most recent file automatically added first, and a second TAB pushing suggests from the most recent to oldest file (reverse ordering).

It is missing just a modification to have l + TAB which has to not add suggestion file, just list all the files from oldest to most recent and after a second TAB, suggest firstly the most recent files from older with ^[[Z' menu-complete.



Solution 1:[1]

To have files/directories completion for any command (unless overridden with a different completion), sorted by modification date (recent to old), as a detailed list -

  1. Add the following to ~/.zshrc :
autoload -Uz compinit
compinit
zmodload zsh/complist

zstyle ':completion:*' file-list all
zstyle ':completion:*' file-sort date
  1. Reload zsh profile - run source ~/.zshrc on an existing terminal session or open a new terminal session for changes to take effect

  2. Trigger detailed list completion - Before hitting TAB - hit space after command. For example l<space><TAB>.

  3. Keep on hitting TAB to select

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1