zsh - 自动完成时如何让 zsh 更喜欢某些文件类型

标签 zsh zshrc oh-my-zsh

我在一个目录中有许多名称相同但文件类型不同的文件:
foo.aux foo.bbl foo.blg foo.log foo.out foo.pdf foo.tex
我希望能够输入 foo[Tab]并让 zsh 始终自动完成到 .tex,然后是 .pdf,然后是 zsh 喜欢的任何顺序。有没有设置这种自动完成首选项?

如果相关,我正在使用 oh-my-zsh。

谢谢你的尽心帮助!

最佳答案

您可以使用 file-patterns设置以您喜欢的任何方式对文件进行分类。对于您的情况,这应该有效:

# First, we define how to categorize the files.
zstyle ':completion:*' file-patterns '
    *.tex(D-^/*):tex-files:"TEX file"
    *.pdf(D-^/*):pdf-files:"PDF file"
    *(D-*):executables:"executable file"
    *(D-/):directories:"directory"
    ^*.(tex|pdf)(D-^/*):files:"other file"
'

# Then, we define in what order they should appear.
zstyle ':completion:*' group-order tex-files pdf-files executables directories files

# Finally, we need to enable group names, or the group order won't work.
zstyle ':completion:*' group-name ''
文档:
  • Glob qualifiers ( (D-^/*) )
  • Completion system configuration
  • 关于zsh - 自动完成时如何让 zsh 更喜欢某些文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34898670/

    相关文章:

    linux - zsh 脚本 [进程完成] 没有返回到 shell

    zsh - Z Shell "autoload"内置 - 它有什么用?

    shell - zsh 提示和主机名

    zshrc - PS1中的zsh随机颜色

    configuration-files - 将所有点文件移出根目录

    zsh - 如何将所有选项卡补全添加到我当前的命令中?

    macos - Zsh 主题在 OSX 上无法正常工作

    zsh - RVM 在 ZSH 中显示 Ruby 版本

    linux - 使用 zsh globbing 进行 grepping 时排除目录

    zsh - 如何使用URL和反斜杠禁用zsh替换/自动完成