# ZSH completion
#
# $Revision: 2.5 $ $Date: 2019-01-30 01:17:03-05 $
# $UUID: 5fd72bc0-5b96-30ed-8666-dc890deb2054 $
#
# Set up new style completion system.  To see examples of the
# old style (compctl based) programmable completion, check
# Misc/compctl-examples in the zsh distribution.
#
# NOTE: use "zstyle -d" to wipe out all style settings.

# The following lines were added by compinstall
zstyle :compinstall filename '/home/vogelke/.zsh/completion.zsh'
autoload -Uz compinit
compinit
# End of lines added by compinstall

# -------------------------------------------------------------------------
# https://grml.org/zsh/zsh-lovers.html
#
# 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):
ZCACHEDIR="$HOME/.zsh/cache"

zstyle ':completion:*' cache-path $ZCACHEDIR
zstyle ':completion:*' use-cache on
compinit -C -d $ZCACHEDIR/compdump

# Speed up file completion.
## https://coderwall.com/p/9fksra/speed-up-your-zsh-completions
zstyle ':completion:*' accept-exact-dirs true

# Tell ZSH to take the first part of the path to be exact, and to avoid
# partial globs.  Now path completions became nearly immediate.
zstyle ':completion:*' accept-exact '*(N)'

# Fuzzy matching of completions for when you mistype them:
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric

# The number of errors allowed by _approximate increases
# with the length of what you've typed so far:
zstyle -e ':completion:*:approximate:*' \
        max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'

# Ignore completion functions for commands you don't have:
zstyle ':completion:*:functions' ignored-patterns '_*'

# Completing process IDs with menu selection:
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*'   force-list always
zstyle ':completion:*:kill:*:processes' command '/bin/ptree'

## Nice menu for basic proc list
## zstyle ':completion:*:kill:*:processes' command \
##        '/bin/ps -o user,pid,ppid,pgid,vsz,rss,time,args'

# If you use a directory as an argument, remove
# the trailing slash (useful in ln):
zstyle ':completion:*' squeeze-slashes true

# Check local directories first.
zstyle ':completion:*:cd:*' tag-order local-directories path-directories

# formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''

# hostname completion
test -f $HOME/.hosts && hosts=(`cat $HOME/.hosts`)
zstyle '*' hosts $hosts

# Filename suffixes to ignore during completion (except after rm)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns \
    '*?.o' '*?.c~' '*?.old' '*?.pro'
# the same for old style completion:
#fignore=(.o .c~ .old .pro)

# ignore completion functions (until the _ignored completer)
zstyle ':completion:*:functions' ignored-patterns '_*'

