2012-02-01 04:37:51 +00:00
|
|
|
#
|
|
|
|
# Sets completion options.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Robby Russell <robby@planetargon.com>
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
|
|
|
|
2012-07-23 19:00:44 +00:00
|
|
|
# Return if requirements are not found.
|
2011-06-01 06:48:26 +00:00
|
|
|
if [[ "$TERM" == 'dumb' ]]; then
|
2012-03-28 16:19:53 +00:00
|
|
|
return 1
|
2011-06-01 06:48:26 +00:00
|
|
|
fi
|
2009-09-22 22:27:28 +00:00
|
|
|
|
2012-08-27 22:49:27 +00:00
|
|
|
# Add zsh-completions to $fpath.
|
|
|
|
fpath=("${0:h}/external/src" $fpath)
|
|
|
|
|
2012-08-04 18:48:32 +00:00
|
|
|
#
|
|
|
|
# Options
|
|
|
|
#
|
|
|
|
|
2011-10-11 02:16:06 +00:00
|
|
|
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.
|
2015-05-05 20:25:26 +00:00
|
|
|
setopt AUTO_MENU # Show completion menu on a successive tab press.
|
2011-10-11 02:16:06 +00:00
|
|
|
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
|
|
|
|
setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash.
|
2017-05-02 08:36:23 +00:00
|
|
|
setopt EXTENDED_GLOB # Needed for file modification glob modifiers with compinit
|
2011-10-11 02:16:06 +00:00
|
|
|
unsetopt MENU_COMPLETE # Do not autoselect the first completion entry.
|
|
|
|
unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor.
|
2009-08-28 18:14:17 +00:00
|
|
|
|
2017-05-02 08:36:23 +00:00
|
|
|
# Load and initialize the completion system ignoring insecure directories with a
|
|
|
|
# cache time of 20 hours, so it should almost always regenerate the first time a
|
|
|
|
# shell is opened each day.
|
|
|
|
autoload -Uz compinit
|
2017-07-08 04:27:18 +00:00
|
|
|
_comp_files=(${ZDOTDIR:-$HOME}/.zcompdump(Nm-20))
|
|
|
|
if (( $#_comp_files )); then
|
2017-05-02 08:36:23 +00:00
|
|
|
compinit -i -C
|
|
|
|
else
|
|
|
|
compinit -i
|
|
|
|
fi
|
2017-07-08 04:27:18 +00:00
|
|
|
unset _comp_files
|
2017-05-02 08:36:23 +00:00
|
|
|
|
2012-08-04 18:48:32 +00:00
|
|
|
#
|
|
|
|
# Styles
|
|
|
|
#
|
|
|
|
|
2015-05-05 20:25:26 +00:00
|
|
|
# Use caching to make completion for commands such as dpkg and apt usable.
|
2011-07-28 19:44:48 +00:00
|
|
|
zstyle ':completion::complete:*' use-cache on
|
2012-09-03 20:13:53 +00:00
|
|
|
zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache"
|
2009-08-28 18:14:17 +00:00
|
|
|
|
2011-07-28 19:44:48 +00:00
|
|
|
# Case-insensitive (all), partial-word, and then substring completion.
|
2012-09-03 20:08:39 +00:00
|
|
|
if zstyle -t ':prezto:module:completion:*' case-sensitive; then
|
2009-10-07 20:01:52 +00:00
|
|
|
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
2011-10-11 02:16:06 +00:00
|
|
|
setopt CASE_GLOB
|
2009-10-07 20:01:52 +00:00
|
|
|
else
|
|
|
|
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
2011-10-11 02:16:06 +00:00
|
|
|
unsetopt CASE_GLOB
|
2009-10-07 20:01:52 +00:00
|
|
|
fi
|
2009-09-06 12:19:33 +00:00
|
|
|
|
2011-07-28 19:44:48 +00:00
|
|
|
# Group matches and describe.
|
|
|
|
zstyle ':completion:*:*:*:*:*' menu select
|
|
|
|
zstyle ':completion:*:matches' group 'yes'
|
|
|
|
zstyle ':completion:*:options' description 'yes'
|
|
|
|
zstyle ':completion:*:options' auto-description '%d'
|
|
|
|
zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
|
|
|
|
zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f'
|
|
|
|
zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
|
|
|
|
zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
|
|
|
|
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
|
|
|
|
zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
|
|
|
|
zstyle ':completion:*' group-name ''
|
|
|
|
zstyle ':completion:*' verbose yes
|
2009-11-08 23:34:02 +00:00
|
|
|
|
2011-07-28 19:44:48 +00:00
|
|
|
# Fuzzy match mistyped completions.
|
|
|
|
zstyle ':completion:*' completer _complete _match _approximate
|
|
|
|
zstyle ':completion:*:match:*' original only
|
|
|
|
zstyle ':completion:*:approximate:*' max-errors 1 numeric
|
2009-08-28 18:14:17 +00:00
|
|
|
|
2017-04-13 09:47:51 +00:00
|
|
|
# Increase the number of errors based on the length of the typed word. But make
|
|
|
|
# sure to cap (at 7) the max-errors to avoid hanging.
|
|
|
|
zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)'
|
2010-11-03 20:57:15 +00:00
|
|
|
|
2011-07-28 19:44:48 +00:00
|
|
|
# Don't complete unavailable commands.
|
|
|
|
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
|
|
|
|
|
|
|
|
# Array completion element sorting.
|
|
|
|
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
|
|
|
|
|
|
|
|
# Directories
|
2012-05-20 22:51:21 +00:00
|
|
|
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
|
2011-07-28 19:44:48 +00:00
|
|
|
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
|
|
|
|
zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
|
|
|
|
zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand'
|
|
|
|
zstyle ':completion:*' squeeze-slashes true
|
|
|
|
|
|
|
|
# History
|
|
|
|
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
|
|
|
|
|
|
|
|
# Environmental Variables
|
|
|
|
zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-}
|
|
|
|
|
2017-07-26 20:16:40 +00:00
|
|
|
# Populate hostname completion. But allow ignoring custom entries from static
|
|
|
|
# */etc/hosts* which might be uninteresting.
|
2017-07-27 17:04:55 +00:00
|
|
|
zstyle -a ':prezto:module:completion:*:hosts' etc-host-ignores '_etc_host_ignores'
|
2017-07-26 20:16:40 +00:00
|
|
|
|
2011-07-28 19:44:48 +00:00
|
|
|
zstyle -e ':completion:*:hosts' hosts 'reply=(
|
2017-08-04 17:54:19 +00:00
|
|
|
${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2> /dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ }
|
|
|
|
${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2> /dev/null))"}%%(\#${_etc_host_ignores:+|${(j:|:)~_etc_host_ignores}})*}
|
|
|
|
${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2> /dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}}
|
2011-07-28 19:44:48 +00:00
|
|
|
)'
|
2010-11-03 20:57:15 +00:00
|
|
|
|
2011-06-01 06:48:26 +00:00
|
|
|
# Don't complete uninteresting users...
|
2010-11-03 20:57:15 +00:00
|
|
|
zstyle ':completion:*:*:*:users' ignored-patterns \
|
2011-07-28 19:44:48 +00:00
|
|
|
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 '_*'
|
2010-11-03 20:57:15 +00:00
|
|
|
|
|
|
|
# ... unless we really want to.
|
|
|
|
zstyle '*' single-ignored show
|
2010-09-26 14:03:44 +00:00
|
|
|
|
2011-07-28 19:44:48 +00:00
|
|
|
# Ignore multiple entries.
|
2012-05-05 21:09:03 +00:00
|
|
|
zstyle ':completion:*:(rm|kill|diff):*' ignore-line other
|
2011-07-28 19:44:48 +00:00
|
|
|
zstyle ':completion:*:rm:*' file-patterns '*:all-files'
|
|
|
|
|
|
|
|
# Kill
|
2015-02-13 05:00:27 +00:00
|
|
|
zstyle ':completion:*:*:*:*:processes' command 'ps -u $LOGNAME -o pid,user,command -w'
|
2011-07-28 19:44:48 +00:00
|
|
|
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01'
|
|
|
|
zstyle ':completion:*:*:kill:*' menu yes select
|
|
|
|
zstyle ':completion:*:*:kill:*' force-list always
|
|
|
|
zstyle ':completion:*:*:kill:*' insert-ids single
|
|
|
|
|
|
|
|
# Man
|
|
|
|
zstyle ':completion:*:manuals' separate-sections true
|
|
|
|
zstyle ':completion:*:manuals.(^1*)' insert-sections true
|
|
|
|
|
|
|
|
# Media Players
|
|
|
|
zstyle ':completion:*:*:mpg123:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories'
|
|
|
|
zstyle ':completion:*:*:mpg321:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories'
|
|
|
|
zstyle ':completion:*:*:ogg123:*' file-patterns '*.(ogg|OGG|flac):ogg\ files *(-/):directories'
|
|
|
|
zstyle ':completion:*:*:mocp:*' file-patterns '*.(wav|WAV|mp3|MP3|ogg|OGG|flac):ogg\ files *(-/):directories'
|
|
|
|
|
|
|
|
# Mutt
|
2012-05-20 23:21:07 +00:00
|
|
|
if [[ -s "$HOME/.mutt/aliases" ]]; then
|
2011-07-28 19:44:48 +00:00
|
|
|
zstyle ':completion:*:*:mutt:*' menu yes select
|
2012-05-20 23:21:07 +00:00
|
|
|
zstyle ':completion:*:mutt:*' users ${${${(f)"$(<"$HOME/.mutt/aliases")"}#alias[[:space:]]}%%[[:space:]]*}
|
2011-07-28 19:44:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# SSH/SCP/RSYNC
|
2017-07-09 02:27:34 +00:00
|
|
|
zstyle ':completion:*:(ssh|scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
|
2011-07-28 19:44:48 +00:00
|
|
|
zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr
|
2012-12-23 16:27:39 +00:00
|
|
|
zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr
|
2012-05-07 10:23:04 +00:00
|
|
|
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
|
|
|
|
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*'
|
|
|
|
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'
|