简体   繁体   中英

zsh issue : have the most recents files and directories near to the prompt and suggested most recent files or directories

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'
  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):

别名“l”别名示例

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:

键入“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:

早期建议

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM