currently, I have this in my .zshrc:

 zstyle ':completion::complete:mpv:*' menu yes select

In addition to using menu for mpv completion, I would like to limit the completions offered to only files with specified file extensions, ie mp4, mp3, ...

how can I integrate that into my existing rule ?

1 Answer 1


The easiest way would be to use the ignored-patterns setting:

zstyle ':completion::complete:mpv:*' ignored-patterns '^(*.(mp4|mp3))'

However, this will also ignore directories not ending in .mp3 or .mp4.

If you still want directories to be completed as normal, then you have to use the slightly more complex file-patterns setting instead:

zstyle ':completion::complete:mpv:*' file-patterns '
  *(D-/):local-directories:"local directory" 
  *.(mp3|mp4)(D-^/):media-files:"media file"

For an explanation of (D-/) and (D-^/), see the Zsh manual's section on glob qualifiers.

  • could we simplify the second rule, if I only want regular files of given type to be offered for completion? All directories can be completely ignored. Jan 22, 2021 at 11:19
  • In that case, you can just use the ignored-patterns rule I posted. Jan 22, 2021 at 11:27
  • OK, that will work. But if I wanted to make sure no directories will ever match, is there a way to have the pattern act only on regular files? Jan 22, 2021 at 11:44
  • From the file-patterns rule, remove the line that generates local directory completions. Jan 22, 2021 at 11:45
  • sorry, but how do i integrate it with the menu yes select? The following does not work: zstyle ':completion::complete:mpv:*' file-patterns '*.(mp3|mp4)(D-^/):media-files:"media file"' menu yes select Jan 22, 2021 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.