]> git.r.bdr.sh - rbdr/dotfiles/blame - zsh/modules/completion.zsh
Use text instead of symbols and emoji
[rbdr/dotfiles] / zsh / modules / completion.zsh
CommitLineData
fa250235
BB
1#
2# Sets completion options.
3#
4# Authors:
5# Robby Russell <robby@planetargon.com>
6# Sorin Ionescu <sorin.ionescu@gmail.com>
7#
8
9# Return if requirements are not found.
10if [[ "$TERM" == 'dumb' ]]; then
11 return 1
12fi
13
14# Load and initialize the completion system ignoring insecure directories.
15autoload -Uz compinit && compinit -i
16
17#
18# Options
19#
20
21setopt COMPLETE_IN_WORD # Complete from both ends of a word.
22setopt ALWAYS_TO_END # Move cursor to the end of a completed word.
23setopt PATH_DIRS # Perform path search even on command names with slashes.
24setopt AUTO_MENU # Show completion menu on a successive tab press.
25setopt AUTO_LIST # Automatically list choices on ambiguous completion.
26setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash.
27unsetopt MENU_COMPLETE # Do not autoselect the first completion entry.
28unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor.
29
30#
31# Styles
32#
33
34# Use caching to make completion for commands such as dpkg and apt usable.
35zstyle ':completion::complete:*' use-cache on
36zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache"
37
38zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
39unsetopt CASE_GLOB
40
41# Group matches and describe.
42zstyle ':completion:*:*:*:*:*' menu select
43zstyle ':completion:*:matches' group 'yes'
44zstyle ':completion:*:options' description 'yes'
45zstyle ':completion:*:options' auto-description '%d'
46zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
47zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f'
48zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
49zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
50zstyle ':completion:*:default' list-prompt '%S%M matches%s'
51zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
52zstyle ':completion:*' group-name ''
53zstyle ':completion:*' verbose yes
54
55# Fuzzy match mistyped completions.
56zstyle ':completion:*' completer _complete _match _approximate
57zstyle ':completion:*:match:*' original only
58zstyle ':completion:*:approximate:*' max-errors 1 numeric
59
60# Increase the number of errors based on the length of the typed word.
61zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'
62
63# Don't complete unavailable commands.
64zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
65
66# Array completion element sorting.
67zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
68
69# Directories
70zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
71zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
72zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
73zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand'
74zstyle ':completion:*' squeeze-slashes true
75
76# History
77zstyle ':completion:*:history-words' stop yes
78zstyle ':completion:*:history-words' remove-all-dups yes
79zstyle ':completion:*:history-words' list false
80zstyle ':completion:*:history-words' menu yes
81
82# Environmental Variables
83zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-}
84
85# Populate hostname completion.
86zstyle -e ':completion:*:hosts' hosts 'reply=(
87 ${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ }
88 ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*}
89 ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}}
90)'
91
92# Don't complete uninteresting users...
93zstyle ':completion:*:*:*:users' ignored-patterns \
94 adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
95 dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
96 hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
97 mailman mailnull mldonkey mysql nagios \
98 named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
99 operator pcap postfix postgres privoxy pulse pvm quagga radvd \
100 rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*'
101
102# ... unless we really want to.
103zstyle '*' single-ignored show
104
105# Ignore multiple entries.
106zstyle ':completion:*:(rm|kill|diff):*' ignore-line other
107zstyle ':completion:*:rm:*' file-patterns '*:all-files'
108
109# Kill
110zstyle ':completion:*:*:*:*:processes' command 'ps -u $LOGNAME -o pid,user,command -w'
111zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01'
112zstyle ':completion:*:*:kill:*' menu yes select
113zstyle ':completion:*:*:kill:*' force-list always
114zstyle ':completion:*:*:kill:*' insert-ids single
115
116# Man
117zstyle ':completion:*:manuals' separate-sections true
118zstyle ':completion:*:manuals.(^1*)' insert-sections true
119
120# SSH/SCP/RSYNC
121zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
122zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr
123zstyle ':completion:*:ssh:*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
124zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr
125zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
126zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*'
127zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'