'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'
- 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) :
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").
- Now, if I type "
l+TAB", I get :
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 :
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 -
- Add the following to
~/.zshrc:
autoload -Uz compinit
compinit
zmodload zsh/complist
zstyle ':completion:*' file-list all
zstyle ':completion:*' file-sort date
Reload zsh profile - run
source ~/.zshrcon an existing terminal session or open a new terminal session for changes to take effectTrigger detailed list completion - Before hitting
TAB- hit space after command. For examplel<space><TAB>.Keep on hitting
TABto 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 |



