compsys: General setup

How to turn on the "new" completion system

Enter the following two commands:

autoload -U compinit

Enabling Caching

Some functions, like _apt and _dpkg, are very slow. You can use a cache in order to proxy the list of results (like the list of available debian packages).

zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache

Helper functions

With helper functions, you can avoid having to complete at all in many cases, but if you do, you might want to fall into menu selection immediately and to have the words sorted by time:

xdvi() { command xdvi ${*:-*.dvi(om[1])} }
zstyle ':completion:*:*:xdvi:*' menu yes select
zstyle ':completion:*:*:xdvi:*' file-sort time

Subscript completion

when completing inside array or association subscripts, the array elements are more useful than parameters so complete them first:

zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters

Picking parameters by the existence of a special completer

Complete the names of parameters we have special completions for in parameter assignments:

zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-}

completing on the prefix

How to complete in the middle of some text ignoring the suffix. (people coming from tcsh might miss this big time).

Just bind TAB to expand-or-complete-prefix:

bindkey '^i' expand-or-complete-prefix

Then /usr/loc<TAB>ljkabcb completes just like if you had /usr/loc<TAB>.

The "Why doesn't zsh's completion realize new commands?" FAQ

Quoting Bart Schaefer from zsh-users #8059:

If you're using compsys, the right way to do this is by adding to your completer zstyle:
_force_rehash() {
  (( CURRENT == 1 )) && rehash
  return 1	# Because we didn't really complete anything

zstyle ':completion:*' completer \
  _oldlist _expand _force_rehash _complete ...
(where "…" is the rest of whatever you already have in that style).
examples/compsys/general.txt · Last modified: 2015/12/08 07:44 by spamkiller