Move into an external dir
[zsh.git] / .zsh / 45_Completion.zsh
1 # -*- mode: sh;-*-
2
3 # autoloads first
4 autoload -Uz compinit
5 autoload -U zsh/complist
6
7 ## General completion technique
8 ## complete as much u can ..
9 zstyle ':completion:*' completer _complete _list _oldlist _expand _ignored _match _correct _approximate _prefix
10 zstyle ':completion:*' completions 1
11 zstyle ':completion:*' glob 1
12
13 # activate color-completion
14 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
15 zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|[._-]=* r:|=*'
16 zstyle ':completion:*' menu select=10
17 zstyle ':completion:*' prompt '%e errors found'
18 zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
19 zstyle ':completion:*' substitute 1
20
21 ## allow one error for every three characters typed in approximate completer
22 zstyle -e ':completion:*:approximate:*' max-errors \
23 'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )'
24
25 ## formatting and messages
26 zstyle ':completion:*' verbose yes
27 #zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}%d%{\e[0m%}'
28 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}%UCompleting %d%{\e[0m%}:%u'
29 zstyle ':completion:*:messages' format $'%{\e[0;31m%}%d%{\e[0m%}'
30 zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for: %d%{\e[0m%}'
31 zstyle ':completion:*' group-name ''
32
33 # ignore duplicate entries
34 zstyle ':completion:*:history-words' remove-all-dups yes
35 zstyle ':completion:*:history-words' stop yes
36
37 # start menu completion only if it could find no unambiguous initial string
38 zstyle ':completion:*:correct:*' insert-unambiguous true
39 zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
40 zstyle ':completion:*:correct:*' original true
41
42 # Group completions according to tags.
43 zstyle ':completion:*' group-name ''
44 zstyle ':completion:*' group-order ''
45
46 zstyle ':completion:*' accept-exact '*(N)'
47
48 ## determine in which order the names (files) should be
49 ## listed and completed when using menu completion.
50 ## `size' to sort them by the size of the file
51 ## `links' to sort them by the number of links to the file
52 ## `modification' or `time' or `date' to sort them by the last modification time
53 ## `access' to sort them by the last access time
54 ## `inode' or `change' to sort them by the last inode change time
55 ## `reverse' to sort in decreasing order
56 ## If the style is set to any other value, or is unset, files will be
57 ## sorted alphabetically by name.
58 zstyle ':completion:*' file-sort name
59
60 zstyle ':completion:*' file-list list=20 insert=10
61
62 ## offer indexes before parameters in subscripts
63 zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
64
65 ## insert all expansions for expand completer
66 zstyle ':completion:*:expand:*' tag-order all-expansions
67
68 ## ignore completion functions (until the _ignored completer)
69 zstyle ':completion:*:functions' ignored-patterns '_*'
70 zstyle ':completion:*' ignored-patterns 'doc-base'
71
72 ## don't complete backup files as executables
73 zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
74
75 ## filename suffixes to ignore during completion (except after rm command)
76 zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns \
77 '*?.(o|c~|old|pro|zwc|sik|bak)' '*~'
78
79 ## completions for some progs. not in default completion system
80 zstyle ':completion:*:*:diffstat:*' file-patterns \
81 '*.(diff|DIFF).gz'
82 zstyle ':completion:*:*:lintian:*' file-patterns \
83 '*.(dsc|deb|udeb|changes)'
84
85 ## on processes completion complete all user processes
86 zstyle ':completion:*:processes' command 'ps -au$USER'
87
88 ## add colors to processes for kill completion
89 zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
90 zstyle ':completion:*:*:kill:*' verbose yes
91
92 # host completion
93 if is42; then
94 [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
95 [[ -r ~/.ssh/debian_known_hosts ]] && _ssh_debian_hosts=(${${${${(f)"$(<$HOME/.ssh/debian_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_debian_hosts=()
96 [[ -r /etc/ssh/ssh_known_hosts ]] && _ssh_etc_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_etc_hosts=()
97 [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
98 [[ -r ${HOME}/.ssh/config ]] && _ssh_config_hosts=(${=${${${${(@M)${(f)"$(<$HOME/.ssh/config)"}:#Host *}#Host }:#*\**}:#*\?*}}) || _ssh_config_hosts=()
99 else
100 _ssh_hosts=()
101 _ssh_debian_hosts=()
102 _ssh_etc_hosts=()
103 _etc_hosts=()
104 _ssh_config_hosts=()
105 fi
106 hosts=(
107 ${HOST}
108 "$_ssh_config_hosts[@]"
109 "$_ssh_hosts[@]"
110 "$_ssh_debian_hosts[@]"
111 "$_ssh_etc_hosts[@]"
112 "$_etc_hosts[@]"
113 localhost
114 )
115 zstyle ':completion::*:*:*:hosts' hosts $hosts
116
117 # Don't complete uninteresting users...
118 zstyle ':completion:*:*:*:users' ignored-patterns \
119 adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
120 dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
121 hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
122 mailman mailnull mldonkey mysql nagios \
123 named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
124 operator pcap postfix postgres privoxy pulse pvm quagga radvd \
125 rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*'
126
127 # ... unless we really want to.
128 zstyle '*' single-ignored show
129
130
131 # Dont complete CVS dirs and lost+found
132 zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
133 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'
134 zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/).svn'
135 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#.svn'
136 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#lost+found'
137
138 # complete manual by their section
139 zstyle ':completion:*:manuals' separate-sections true
140 zstyle ':completion:*:manuals.*' insert-sections true
141 zstyle ':completion:*:man:*' menu yes select
142
143 # Search path for sudo completion
144 zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
145 /usr/local/bin \
146 /usr/sbin \
147 /usr/bin \
148 /sbin \
149 /bin \
150 /usr/X11R6/bin
151
152
153 # SSH/SCP/RSYNC
154 zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
155 zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr
156 zstyle ':completion:*:ssh:*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
157 zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr
158 zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
159 zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*'
160 zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'
161
162 ## completion caching
163 zstyle ':completion::complete:*' use-cache 1
164 zstyle ':completion::complete:*' cache-path ${ZDOTDIR}/.zcompcache
165
166 compinit -d ${ZDOTDIR}/var/.zcompdump
167
168 ## generic completions for programs which understand GNU long options(--help)
169 compdef _gnu_generic make df du gpg lintian
170
171 # Complete them as ssh
172 compdef _ssh ssha=ssh
173 compdef _ssh sshc=ssh
174 compdef _hosts ssha
175
176 _debian_rules() { words=(make -f debian/rules) _make }
177 compdef _debian_rules debian/rules