Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File completion priorities in ZSH

I have a shell pattern that marks some files as "boring" namely backup files, pyo files, vim backups, autogenerated directories and the like. Let's call it $BORING_STUFF.

zstyle ':completion:*' file-patterns \ 
    '%p:globbed-items' \
    '*(^-/):regular-files' \
    '*(^-/):boring-files' \
    '.*(^-/):hidden-files' \
    '*(-/):regular-directories' \
    '*(-/):boring-directories' \
    '.*(-/):hidden-directories'

In this case, I have the scope of each group also constrained by applicable ignore-patterns. (Such that boring-files contains only boring files and regular-files does not contain boring files)

I'd like bold items to always show up, and other items only show up if there are no other matches. (Aka. touch <tab> will show regular directories and regular files but not hidden files, while touch .<tab> will show hidden files.)

  • globbed items
  • directories
    • regular directories
    • boring directories
    • hidden directories
  • files
    • regular files
    • boring files
    • hidden files
like image 598
PythonNut Avatar asked Nov 11 '22 04:11

PythonNut


1 Answers

Here we go.

setopt extended_glob
zstyle ':completion:*' file-patterns \
  "^($BORING_FILES|.*)(-/):directories:normal\ directories %p~($BORING_FILES|.*)(^-/):globbed-files:normal\ files" \
  "^($BORING_FILES|.*)(^-/):noglob-files:noglob\ files" \
  ".*~($BORING_FILES)(^-/):hidden-files:hidden\ files .*~($BORING_FILES)(-/):hidden-directories:hidden\ directories" \
  "($BORING_FILES)(^-/):boring-files:boring\ files ($BORING_FILES)(-/):boring-directories:boring\ directories" \

zstyle ':completion:*' group-order \
  builtins expansions aliases functions commands globbed-files \
  directories hidden-files hidden-directories \
  boring-files boring-directories keywords viewable
like image 126
PythonNut Avatar answered Dec 20 '22 04:12

PythonNut