#StackBounty: #shell #zsh #ls #autocomplete #iterm2 zsh completion: have the most recents files and directories near to the prompt and …

Bounty: 50

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

autoload -Uz compinit
compinit
# Colorize completions using default `ls` colors.
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"

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

# To get new binaries into PATH
zstyle ':completion:*' rehash true

# Disable prompt disappearing on multi-lines
export COMPLETION_WAITING_DOTS="false"

zstyle ':completion:*' file-sort date reverse

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?

Update

Below an illustration of my issue:

enter image description here

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

alias l='grc -es --colour=auto ls --color -Gh -C -lrt'

The problem is that once I type again "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, in both cases, i.e in the case where prompt is located on top and if I have the prompt below the suggestions.

That is to say, I would like to get displayed the most modified recent files (like if I did a "ls -lrt") in first and second less recent after a second completion TAB and etc.

EDIT 1:

The options

autoload -U compinit
compinit
zstyle ':completion:*' file-sort modification reverse

(reverse here to see newest files in the end of the list, because the upper part might not be visible on the screen.)

But If I do it like for example on this screen below :

last modified on below

this is not what I want : I would like the file Fisher_GCph_WL_XSAF appears in first near to the prompt, after, Fisher_GCs_WL_TSAF and so on (that is to say, the reverse showed order).

How to modifiy this behavior ? Having in all situations the most recent files and directory near from the prompt ?

It seems that everything depends if the list of files and directories can be contained all into the iTerm2 terminal window : if not, the order is not reversed, if yes, it is reversed. I don’t know what to do.

EDIT 2: I can confirm what I said above.

With the option zstyle ':completion:*' file-sort date or
zstyle ':completion:*' file-sort modification :

  1. If all the list of files and directories can’t be displayed in the terminal window, the most recent files and directories doesn’t appear near to the prompt when I do a "l +TAB" (with "l" the alias defined above in the post).
  2. If all the list of files and directories can be displayed in the terminal window, the most recent files and directories appear near to the prompt when I do a "l +TAB".

How to manage to get the same behavior in both cases ? : the most recent files and directories always near to the prompt ?

EDIT 3: I realize that the ordering display depends if all the listed files can be contained in the iTerm2 pane where I perform the command alias ‘l‘ . I recall that alias ‘l‘ is defined by :

alias l='grc -es --colour=auto ls --color -Gh -C -lrt'

Option 1) if all files listing can be contained, then the more recent files/directories are near to the prompt when performing ‘l+TAB

Option 2) if there is a long list of files/directories, ‘l+TAB‘ is moved bottom and just above the oldest ordering are near to the prompt.

This is this option 2) that I want to fix, i.e having with the more recent ordering files/directories just above the prompt.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.