¿Cómo puedo completar la pestaña zsh en "vi **/foo?""para hacer coincidir y completar el primer archivo que coincida con "foo*" en cualquier lugar del directorio actual?

¿Cómo puedo completar la pestaña zsh en "vi **/foo?""para hacer coincidir y completar el primer archivo que coincida con "foo*" en cualquier lugar del directorio actual?

¿Cómo consigo que la finalización de la pestaña zsh cat **/foo<TAB>coincida y complete el primer archivo coincidente foo*en cualquier subdirectorio del directorio actual?

Por ejemplo, haga esto mientras está dentro de un directorio de prueba nuevo: (nuevamente, esto es zsh)

% mkdir aaa bbb ccc
% touch aaa/foo bbb/foo ccc/foo
% cat **/f<TAB>

Lo que quiero cuando presiono <TAB>esa última línea es que mi pantalla termine viéndose así:

% cat aaa/foo_                 # filled in the first match; "_" is the cursor
aaa/foo  bbb/foo  ccc/foo      # and here is the list of all matches

Lo intenté setopt GLOB_COMPLETE, pero eso no hizo lo que quería.

Respuesta1

Agregue lo siguiente a su ~/.zshrcarchivo (o péguelo en la línea de comando para probarlo):

# Load Zsh's new completion system.
autoload -Uz compinit && compinit

# Bind Tab to complete-word instead of 
# expand-or-complete. This is required for 
# the new completion system to work 
# correctly.
bindkey '^I' complete-word

# Add the _match completer.
# We add it after _expand & _complete, so it 
# will get called only once those two have 
# failed.
# _match_ completes patterns only, which 
# _expand can do, too, (which is why we call 
# _match_ only when _expand & _complete 
# fail), but _match adds an extra * at the 
# cursor position. Without that, the pattern 
# **/f would not match {aaa,bbb,ccc}/foo
zstyle ':completion:*' completer \
    _expand _complete _match _ignored

# Let all possible completions for a partial 
# path be listed, rather than just the first 
# one.
zstyle ':completion:*' list-suffixes true

Luego, cuando escriba cat **/fy presione Tab, obtendrá el siguiente resultado:

% cat aaa/foo
aaa/foo  bbb/foo  ccc/foo
**/f

Documentación:

Ver también:Una guía del usuario para Z-Shell: finalización, antigua y nueva

información relacionada