On MacOS Big Sur 11.3, here is my .zshrc
. I would like to get the latest modified or create files and directories near to the prompt (sorted from the most recent up to the oldest ones). Here my current config in ~/.zshrc
:
# ZSH completion
autoload -Uz compinit
compinit
# Colorize completions using default `ls` colors.
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
# Zsh reverse auto-completion
zmodload zsh/complist
bindkey '^[[Z' reverse-menu-complete
# To get new binaries into PATH
zstyle ':completion:*' rehash true
zstyle ':completion:*:complete:(ls):*' file-sort date reverse
zstyle ':completion:*:complete:(cd):*' file-sort date reverse
zstyle ':completion:*:complete:(cp):*' file-sort date reverse
zstyle ':completion:*:complete:(mv):*' file-sort date reverse
# Variables not very well known
# Disable prompt disappearing on multi-lines
export COMPLETION_WAITING_DOTS="false"
The issue is that when I press TAB after a "l" which is actually the alias:
alias l='grc -es --colour=auto ls --color -Gh -C -lrt'
grc
is a tool to colorify the files.
Indeed, I have not as the first result the most recent modified or created file or directory which are suggested.
Which option could I add in zsh completion
to get as first results after pressing TAB these last recent (modification or creation) files or directories?
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.
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
.
completion
string (some usingmodification
, some usingdate
). The final question seems to be "How to calculate the size of the terminal emulation window and compare it to the number of lines required to list all files in the current directory"; you might want to ask that in a separate question? The answer to your title is already given:zstyle ':completion:*' file-sort date
, then typel
followed byTAB
, and the first suggestion is the newest file. – Drudgemenu
section of the compsysstandard style
documentation; tryzstyle ':completion:*' menu yes=long select
to show the menu when there's too many options to fit on the screen. Alternatively always try settingAUTO_MENU
andMENU_COMPLETE
options (when testing it seems I need both, not either-or, but check the man pages). If none of that's helpful, can you clarify in the question so it's clear what you want :) – Drudgelist-colors
which I think might do what you want. As to why three of the items seem to be selected in your screenshot, that'd be a different question entirely :) – Drudge3.2
and3.3
the behavior's exactly as specified: you've gotreverse
in yourzstyle
(see thefile-sort
section of the Completion System's Standard Styles documentation). Why does removingreverse
from both lines of yourzstyle
not fix this? – Drudge