initial
[zsh.git] / .zsh / 45_Completion.zsh
1 # -*- mode: sh;-*-
2
3 ## General completion technique
4 ## complete as much u can ..
5 zstyle ':completion:*' completer _complete _list _oldlist _expand _ignored _match _correct _approximate _prefix
6 zstyle ':completion:*' completions 1
7 zstyle ':completion:*' glob 1
8
9 # activate color-completion
10 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
11 zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|[._-]=* r:|=*'
12 zstyle ':completion:*' menu select=10
13 zstyle ':completion:*' prompt '%e errors found'
14 zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
15 zstyle ':completion:*' substitute 1
16
17 ## allow one error for every three characters typed in approximate completer
18 zstyle -e ':completion:*:approximate:*' max-errors \
19 'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )'
20
21 ## formatting and messages
22 #zstyle ':completion:*' verbose yes
23 #zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}%d%{\e[0m%}'
24 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}%UCompleting %d%{\e[0m%}:%u'
25 zstyle ':completion:*:messages' format $'%{\e[0;31m%}%d%{\e[0m%}'
26 zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for: %d%{\e[0m%}'
27 zstyle ':completion:*' group-name ''
28
29 # ignore duplicate entries
30 zstyle ':completion:*:history-words' remove-all-dups yes
31 zstyle ':completion:*:history-words' stop yes
32
33 # start menu completion only if it could find no unambiguous initial string
34 zstyle ':completion:*:correct:*' insert-unambiguous true
35 zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
36 zstyle ':completion:*:correct:*' original true
37
38 # Group completions according to tags.
39 zstyle ':completion:*' group-name ''
40 zstyle ':completion:*' group-order ''
41
42 zstyle ':completion:*' accept-exact '*(N)'
43
44 ## completion caching
45 zstyle ':completion::complete:*' use-cache 1
46 zstyle ':completion::complete:*' cache-path ${ZDOTDIR}/.zcompcache
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
91 # host completion
92 [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
93 [[ -r ~/.ssh/debian_known_hosts ]] && _ssh_debian_hosts=(${${${${(f)"$(<$HOME/.ssh/debian_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_debian_hosts=()
94 [[ -r /etc/ssh/ssh_known_hosts ]] && _ssh_etc_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_etc_hosts=()
95 [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
96
97 hosts=(
98 ${HOST}
99 "$_ssh_hosts[@]"
100 "$_ssh_debian_hosts[@]"
101 "$_ssh_etc_hosts[@]"
102 "$_etc_hosts[@]"
103 localhost
104 )
105 zstyle ':completion:*:hosts' hosts $hosts
106
107 # Dont complete CVS dirs and lost+found
108 zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
109 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'
110 zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/).svn'
111 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#.svn'
112 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#lost+found'
113
114 # complete manual by their section
115 zstyle ':completion:*:manuals' separate-sections true
116 zstyle ':completion:*:manuals.*' insert-sections true
117 zstyle ':completion:*:man:*' menu yes select
118
119 # Search path for sudo completion
120 zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
121 /usr/local/bin \
122 /usr/sbin \
123 /usr/bin \
124 /sbin \
125 /bin \
126 /usr/X11R6/bin
127
128
129 autoload -Uz compinit
130 compinit
131
132 ## generic completions for programs which understand GNU long options(--help)
133 compdef _gnu_generic make df du gpg lintian
134
135 # Complete them as ssh
136 compdef _ssh ssha=ssh
137 compdef _ssh sshc=ssh
138 compdef _hosts ssha
139
140 _debian_rules() { words=(make -f debian/rules) _make }
141 compdef _debian_rules debian/rules
142
143 # git related
144 compdef g=git
145 compdef _git gst=git-status
146 compdef _git gl=git-pull
147 compdef _git gup=git-fetch
148 compdef _git gp=git-push
149 gdv() { git diff -w "$@" }
150 compdef _git gdv=git-diff
151 compdef _git gc=git-commit
152 compdef _git gca=git-commit
153 compdef _git gco=git-checkout
154 compdef _git gr=git-remote
155 compdef _git grv=git-remote
156 compdef _git grmv=git-remote
157 compdef _git grrm=git-remote
158 compdef _git grset=git-remote
159 compdef _git grset=git-remote
160 compdef _git gb=git-branch
161 compdef _git gba=git-branch
162 compdef gcount=git
163 compdef _git gcp=git-cherry-pick
164 compdef _git glg=git-log
165 compdef _git glgg=git-log
166 compdef _git glgga=git-log
167 compdef _git gss=git-status
168 compdef _git ga=git-add
169 compdef _git gm=git-merge
170 compdef ggpull=git
171 compdef ggpush=git
172 compdef ggpnp=git