4

I have many files with the same name but different filetype all in one directory:

foo.aux foo.bbl foo.blg foo.log foo.out foo.pdf foo.tex

I would like to be able to type foo[Tab] and have zsh always autocomplete to .tex, then .pdf, then whatever order zsh likes. Is there anyway of setting this kind of autocompletion preferences?

I am using oh-my-zsh if that is relevant.

Thanks for any help you can offer!

campbellC
  • 59
  • 1
  • 5
  • Probably asking too much from `_path_files`, which sorts results according to `file-sort` (search "file-sort" in http://zsh.sourceforge.net/Doc/Release/Completion-System.html), which could be `size`, `links`, `modification`, etc., just the standard ones. – 4ae1e1 Jan 20 '16 at 18:26
  • 1
    For certain commands though, you can write your own completion def to prefer some extensions over the others. Hint: use `files -g '*.tex'` for tex, then `files -g '*.pdf'` for pdf, etc. – 4ae1e1 Jan 20 '16 at 18:28
  • @4ae1e1 Thanks very much I will go for that as I am most of the time using vim for my tex files. Understandable that it's not doable generally. Thanks for the help! – campbellC Jan 21 '16 at 13:30

1 Answers1

0

You can use the file-patterns setting to categorize files in whatever way you like. For your case, this should work:

# 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 ''

Documentation:

Marlon Richert
  • 5,250
  • 1
  • 18
  • 27