Como faço para que a conclusão da guia zsh cat **/foo<TAB>
corresponda e conclua a correspondência do primeiro arquivo foo*
em qualquer subdiretório no diretório atual?
Por exemplo, faça isso dentro de um novo diretório de teste: (novamente, este é zsh)
% mkdir aaa bbb ccc
% touch aaa/foo bbb/foo ccc/foo
% cat **/f<TAB>
O que eu quero quando clico <TAB>
na última linha é que minha tela fique assim:
% 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
Eu tentei setopt GLOB_COMPLETE
, mas não fez o que eu queria.
Responder1
Adicione o seguinte ao seu ~/.zshrc
arquivo (ou cole-o na linha de comando para testar):
# 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
Então, ao digitar cat **/f
e pressionar Tab, você obterá a seguinte saída:
% cat aaa/foo
aaa/foo bbb/foo ccc/foo
**/f
Documentação:
Veja também:Guia do usuário do Z-Shell: conclusão, antigo e novo