# Add zsh-completions to $fpath.
fpath=("${0:h}/usr/share/zsh/site-functions" $fpath)

setopt COMPLETE_IN_WORD    # Complete from both ends of a word.
setopt ALWAYS_TO_END       # Move cursor to the end of a completed word.
setopt PATH_DIRS           # Perform path search even on command names with slashes.
setopt AUTO_MENU           # Show completion menu on a successive tab press.
setopt AUTO_LIST           # Automatically list choices on ambiguous completion.
setopt EXTENDED_GLOB       # Needed for file modification glob modifiers with compinit
setopt NO_NOMATCH          # [default] unmatched patterns are left unchanged
setopt GLOB_COMPLETE       # Complete without expanding glob
setopt NOAUTOREMOVESLASH   # Do not remove postfix slash of command line
unsetopt MENU_COMPLETE     # Do not autoselect the first completion entry.
unsetopt FLOW_CONTROL      # Disable start/stop characters in shell editor.

autoload -Uz compinit
_comp_path="${XDG_CACHE_HOME:-$HOME/.cache}/zcompdump"
# #q expands globs in conditional expressions
if [[ $_comp_path(#qNmh-20) ]]; then
  # -C (skip function check) implies -i (skip security check).
  compinit -C -d "$_comp_path"
else
  mkdir -p "$_comp_path:h"
  compinit -i -d "$_comp_path"
  # Keep $_comp_path younger than cache time even if it isn't regenerated.
  touch "$_comp_path"
fi
unset _comp_path

zstyle ':completion:*' matcher-list ''    '+m:{[:lower:]}={[:upper:]}' '+m:{[:upper:]}={[:lower:]}' '+m:{_-}={-_}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*:default'		      list-colors ${(s.:.)LS_COLORS}
zstyle -e ':completion:*'                     special-dirs '[[ $PREFIX = (../)#(..) ]] && reply=(..)'
zstyle ':completion:*:complete:(cd|pushd):*'  tag-order 'local-directories named-directories'
zstyle ':completion:*'                        group-name ''
zstyle ':completion:*:descriptions'	      format '%F{yellow}%d %f'
zstyle ':completion:*'                        menu select
zstyle ':completion::complete:*'              use-cache on
zstyle ':completion::complete:*'              cache-path "$XDG_CACHE_HOME/zcompcache"
zstyle ':completion:*:matches'                group 'yes'
zstyle ':completion:*:options'                description 'yes'
zstyle ':completion:*:options'                auto-description '%d'
zstyle ':completion:*:default'                list-prompt '%S%M matches%s'
zstyle ':completion:*'                        verbose yes
zstyle ':completion:*'                        completer _complete _match _approximate
zstyle ':completion:*:match:*'                original only
zstyle ':completion:*:approximate:*'	      max-errors 1 numeric
zstyle -e ':completion:*:approximate:*'       max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)'
zstyle ':completion:*:functions'	      ignored-patterns '(_*|pre(cmd|exec))'
zstyle ':completion:*:*:-subscript-:*'	      tag-order indexes parameters
zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
zstyle ':completion:*:-tilde-:*'              group-order 'named-directories' 'path-directories' 'users' 'expand'
zstyle ':completion:*:history-words'          stop yes
zstyle ':completion:*:history-words'          remove-all-dups yes
zstyle ':completion:*:history-words'          list false
zstyle ':completion:*:history-words'          menu yes
zstyle ':completion::*:(-command-|export):*'  fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-}
zstyle ':completion:*:(rm|kill|diff):*'	      ignore-line other
zstyle ':completion:*:rm:*'		      file-patterns '*:all-files'
zstyle ':completion:*:*:*:*:processes'	      command 'ps -u $LOGNAME -o pid,user,command -w'
zstyle ':completion:*:*:kill:*:processes'     list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01'
zstyle ':completion:*:(killall|pkill|kill):*' menu yes select
zstyle ':completion:*:(killall|pkill|kill):*' force-list always
zstyle ':completion:*:(killall|pkill|kill):*' insert-ids single
zstyle ':completion:*:man:*'		      menu yes select
zstyle ':completion:*:manuals'		      separate-sections true
zstyle ':completion:*:manuals.(^1*)'	      insert-sections true
zstyle ':completion:*:parameters'             list-colors '=*=34'
zstyle ':completion:*:commands'               list-colors '=*=32'
zstyle ':completion:*:builtins'               list-colors '=*=1;38;5;142'
zstyle ':completion:*:aliases'                list-colors '=*=2;38;5;120'
zstyle ':completion:*:options'                list-colors '=^(-- *)=34'
zstyle ':completion:*:default'                list-colors '=(#b)*(-- *)=36=33' '=*=36'
zstyle ':completion:*'                        rehash true
zstyle ':completion:*'                        list-separator "  "
zstyle ':completion:*'			      list-dirs-first true

zstyle -e ':completion:*:hosts' hosts 'reply=()'

# Don't complete uninteresting users...
zstyle ':completion:*:*:*:users' ignored-patterns \
  adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
  dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
  hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
  mailman mailnull mldonkey mysql nagios \
  named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
  operator pcap postfix postgres privoxy pulse pvm quagga radvd \
  rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*'
