1

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 ?

2

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

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

However, this then also ignores directories not ending in .mp3 or .mp4.

If we still want directories to be completed as normal, then we 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.

7
  • 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. – 400 the Cat Jan 22 at 11:19
  • In that case, you can just use the ignored-patterns rule I posted. – Marlon Richert Jan 22 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? – 400 the Cat Jan 22 at 11:44
  • From the file-patterns rule, remove the line that generates local directory completions. – Marlon Richert Jan 22 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 – 400 the Cat Jan 22 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.