magic space binding
[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 else
99 _ssh_hosts=()
100 _ssh_debian_hosts=()
101 _ssh_etc_hosts=()
102 _etc_hosts=()
103 fi
104 hosts=(
105 ${HOST}
106 "$_ssh_hosts[@]"
107 "$_ssh_debian_hosts[@]"
108 "$_ssh_etc_hosts[@]"
109 "$_etc_hosts[@]"
110 localhost
111 )
112 zstyle ':completion:*:hosts' hosts $hosts
113
114 # Don't complete uninteresting users...
115 zstyle ':completion:*:*:*:users' ignored-patterns \
116 adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
117 dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
118 hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
119 mailman mailnull mldonkey mysql nagios \
120 named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
121 operator pcap postfix postgres privoxy pulse pvm quagga radvd \
122 rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*'
123
124 # ... unless we really want to.
125 zstyle '*' single-ignored show
126
127
128 # Dont complete CVS dirs and lost+found
129 zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
130 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'
131 zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/).svn'
132 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#.svn'
133 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#lost+found'
134
135 # complete manual by their section
136 zstyle ':completion:*:manuals' separate-sections true
137 zstyle ':completion:*:manuals.*' insert-sections true
138 zstyle ':completion:*:man:*' menu yes select
139
140 # Search path for sudo completion
141 zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
142 /usr/local/bin \
143 /usr/sbin \
144 /usr/bin \
145 /sbin \
146 /bin \
147 /usr/X11R6/bin
148
149
150 # SSH/SCP/RSYNC
151 zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
152 zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr
153 zstyle ':completion:*:ssh:*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
154 zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr
155 zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
156 zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*'
157 zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'
158
159 ## completion caching
160 zstyle ':completion::complete:*' use-cache 1
161 zstyle ':completion::complete:*' cache-path ${ZDOTDIR}/.zcompcache
162
163 compinit -d ${ZDOTDIR}/var/.zcompdump
164
165 ## generic completions for programs which understand GNU long options(--help)
166 compdef _gnu_generic make df du gpg lintian
167
168 # Complete them as ssh
169 compdef _ssh ssha=ssh
170 compdef _ssh sshc=ssh
171 compdef _hosts ssha
172
173 _debian_rules() { words=(make -f debian/rules) _make }
174 compdef _debian_rules debian/rules
175
176 if is434; then
177 # git related
178 compdef g=git
179 compdef _git gst=git-status
180 compdef _git gl=git-pull
181 compdef _git gup=git-fetch
182 compdef _git gp=git-push
183 gdv() { git diff -w "$@" }
184 compdef _git gdv=git-diff
185 compdef _git gc=git-commit
186 compdef _git gca=git-commit
187 compdef _git gco=git-checkout
188 compdef _git gr=git-remote
189 compdef _git grv=git-remote
190 compdef _git grmv=git-remote
191 compdef _git grrm=git-remote
192 compdef _git grset=git-remote
193 compdef _git grset=git-remote
194 compdef _git gb=git-branch
195 compdef _git gba=git-branch
196 compdef gcount=git
197 compdef _git gcp=git-cherry-pick
198 compdef _git glg=git-log
199 compdef _git glgg=git-log
200 compdef _git glgga=git-log
201 compdef _git gss=git-status
202 compdef _git ga=git-add
203 compdef _git gm=git-merge
204 compdef ggpull=git
205 compdef ggpush=git
206 compdef ggpnp=git
207 fi