zshuper/modules/compinit.zsh

60 lines
2.0 KiB
Bash
Raw Normal View History

2018-02-03 02:29:33 +02:00
#
# Autocompletions
#
# Also see https://gist.github.com/ctechols/ca1035271ad134841284
autoload -Uz compinit
if [[ -n ${HOME}/.zcompdump(#qN.mh+24) ]]; then
compinit;
else
compinit -C;
fi;
# Make it case insensitive
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# Completion menu
setopt menu_complete
zstyle ':completion:*' menu select
zstyle ':completion:*:warnings' format 'Nuffin there :('
zstyle ':completion:*' expand prefix suffix
zstyle ':completion:*' completer _expand_alias _complete _approximate
zstyle ':completion:*:approximate:*' max-errors 4
zstyle ':completion:*' special-dirs true
# Completion correction
setopt correct
zstyle ':completion:*:correct:*' insert-unambiguous true
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
zstyle ':completion:*:correct:*' original true
zstyle ':completion:correct:' prompt 'correct to: %e'
# Completion cache
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path "${ZSHUPER_DIR}/.cache/completion"
# Username completion
ignored_users=(
$(cat /etc/passwd | cut -d':' -f1,6 | sed 's/:/ /g' | awk '$2 !~ /^ *\/home/ {print $1}')
)
zstyle ':completion:*:*:*:users' ignored-patterns $ignored_users
# Process killing
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:*:*:processes' command "ps -u $(whoami) -o pid,user,comm -w -w"
# Hostname completions
[ -r ~/.ssh/known_hosts ] && _ssh_known_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_known_hosts=()
[ -r ~/.ssh/config ] && _ssh_hosts=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_hosts=()
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
hosts=(
"${_ssh_known_hosts[@]}"
"${_ssh_hosts[@]}"
"$_etc_hosts[@]"
localhost
)
zstyle ':completion:*' hosts $hosts