#!zsh # Don't run this function outside of ZLE [[ -v WIDGET ]] || return # Give a message in case it takes too long to load completions zle -M 'Loading completions...' # Undo the setup from this function unfunction $funcstack[1] zle -D $WIDGET # Push Tab back onto the stack so that completion will be triggered once we're finished. zle -U $KEYS # Actually initialize completions zmodload zsh/complist autoload -Uz compinit compinit -d ${XDG_CACHE_DIR:-$HOME/.cache}/zcompdump # Enable more caching zstyle ':completion:*' use-cache yes zstyle ':completion:*' cache-path ${XDG_CACHE_DIR:-$HOME/.cache}/zcompcache # Enable completion menu zstyle ':completion:*' menu select true # Use ls colors in completion as well zstyle -e ':completion:*' list-colors 'reply=("${(s.:.)LS_COLORS}")' # Completion groups zstyle ':completion:*' group-name '' zstyle ':completion:*:*:-command-:*' group-order aliases global-aliases functions builtins reserved-words commands zstyle ':completion:*' group-order original corrections expansions all-expansions zstyle ':completion:*' list-dirs-first true # Make messages and warnings a bit nicer. zstyle ':completion:*:descriptions' format '➤ %B%d%b (%B%F{cyan}%n%f%b)' zstyle ':completion:*:messages' format "%F{yellow}%d%f" zstyle ':completion:*:warnings' format '%F{red}No %d completions found.%f' # Show and insert `man` sections. zstyle ':completion:*' insert-sections yes zstyle ':completion:*' separate-sections yes # Complete hosts from ssh_config and known_hosts files zstyle -e 'completion:*:(mosh|ssh|scp|sftp|rsh|rsync):*:hosts' hosts 'reply=( ${${(M)${(f)"$(< ~/.ssh/config)"}:#Host [^*!?]##}#Host } ${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|<0->)(N) /dev/null)"}%%[# ]*}//,/ } )' ## Menuselect keybindings # Cancel menu completion with escape bindkey -M menuselect '^[' send-break # Navigate by sections bindkey -M menuselect '^N' vi-forward-blank-word bindkey -M menuselect '^P' vi-backward-blank-word # Navigate by screenfuls bindkey -M menuselect '^d' forward-word bindkey -M menuselect '^u' backward-word