]> git.madduck.net Git - etc/zsh.git/blob - .zsh/zshrc/80-completion

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

4803d5cb184d1b02124f9e1134e3c17312510433
[etc/zsh.git] / .zsh / zshrc / 80-completion
1 #
2 # Set up completion
3 #
4 # Copyright © 1994–2017 martin f. krafft <madduck@madduck.net>
5 # Released under the terms of the Artistic Licence 2.0
6 #
7 # Source repository: http://git.madduck.net/v/etc/zsh.git
8 #
9
10 ### INITIALISATION
11
12 zstyle :compinstall filename "$ZDOTDIR/zshrc/80-completion"
13
14 autoload -Uz compinit
15 compinit -d $ZVARDIR/comp-$HOSTS
16
17 # load fancy completion list and menu handler
18 zmodload zsh/complist
19
20 # avoid old-style completion (compctl)
21 zstyle ':completion:*' use-compctl false
22
23 # cache results
24 zstyle ':completion:*' use-cache on
25 zstyle ':completion:*' cache-path $ZVARDIR/compcache-${HOST}
26
27 ### OPTIONS
28
29 # show the list of completions right away when there's an ambiguous prefix
30 # note that there's also the 'list' zstyle, which could override this
31 setopt auto_list
32 setopt no_list_ambiguous
33
34 # use menu after the second completion request
35 # cf. also the 'menu' zstyle, which eclipses this
36 setopt auto_menu
37
38 # these mess with the aforementioned behaviour, make sure they're off
39 setopt no_menu_complete no_bash_auto_list
40
41 # make the completion list smaller by printing the matches in columns with
42 # different widths.
43 setopt list_packed
44
45 # do not recognise exact matches even if they're ambiguous
46 # (we don't want this because /var/log/sys<tab> should also
47 # offer /var/log/syslog…)
48 setopt no_rec_exact
49
50 # move cursor to end of word being completed
51 setopt always_to_end
52
53 # be magic about adding/removing final characters on tab completion
54 setopt auto_param_keys auto_param_slash auto_remove_slash
55
56 # allow completion to happen in the middle of a word
57 setopt complete_in_word
58
59 ### COMPLETERS
60
61 # set the list of completers
62 zstyle ':completion:*' completer \
63   _expand_alias _expand \
64   _complete _prefix:-complete \
65   _approximate _prefix:-approximate \
66   _match _ignored
67 zstyle ':completion:*:prefix-complete:*' completer _complete
68 zstyle ':completion:*:prefix-approximate:*' completer _approximate
69
70 # configure the _expand completer
71 bindkey '^i' complete-word
72 zstyle ':completion::expand:*' tag-order 'expansions all-expansions original'
73
74 # do approximated completion, allowing 1 error per three characters
75 zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
76
77 ### TRIM OUTPUT OF IGNORED PATTERNS
78
79 # functions which start with _ are internal and ignored
80 zstyle ':completion:*:*:-command-:*' tag-order 'functions:-non-comp'
81 zstyle ':completion:*:functions-non-comp' ignored-patterns '_*'
82
83 # ignore working and backup copies, and compiled objects
84 zstyle ':completion:*:argument-rest:' file-patterns '
85   *(-/):directories:directories
86   (*.(ba#k|old)|*~):backup-files:"backup files"
87   *.(l#[oa]|py[co]|zwc):compiled-files:"compiled files"
88   *.te#mp:temp-files:"temp files"
89   .*.sw?:vim-swap-files:"vim swap files"
90   %p:globbed-files *:all-files
91   '
92 zstyle ':completion:*:argument-rest:(all|globbed)-files' ignored-patterns \
93   '((*.(ba#k|old)|*~)|*.(l#[oa]|py[co]|zwc)|*.te#mp|.*.sw?|*(-/))'
94 #TODO directories not ignored in files output:
95 ####  fishbowl:/tmp/cdt.6kIDed% cat <tab>
96 ####  directories
97 ####  foobar/
98 ####  backup files
99 ####  foo.bk                     foo.old
100 ####  compiled files
101 ####  foo.a    foo.la   foo.lo   foo.o    foo.pyc  foo.zwc
102 ####  temp files
103 ####  foo.tmp
104 ####  files
105 ####  foobar/      foo.c        foo.txt
106
107 #zstyle ':completion:*:argument*' tag-order "
108 #  globbed-files files all-files
109 #  directories
110 #  backup-files
111 #  compiled-files
112 #  temp-files
113 #  vim-swap-files
114 #  "
115 zstyle ':completion:*:argument*' group-order \
116   vim-swap-files \
117   globbed-files files all-files \
118   directories \
119   backup-files \
120   compiled-files \
121   temp-files \
122 #end
123 #TODO no effect on ordering yet
124
125 zstyle ':completion:*:argument*' group-order vim-swap-files directories \
126   globbed-files files all-files backup-files compiled-files temp-files
127
128 resource() { source $ZDOTDIR/zshrc/80-completion; zle -M "resourced"; }
129 zle -N resource
130 bindkey '\er' resource
131
132 # do not offer files already specified on the line
133 zstyle ':completion:*:rm' ignore-line yes
134
135 # do not offer current directory as completion in ../
136 zstyle ':completion:*' ignore-parents parent pwd
137
138 # http://xana.scru.org/2005/08/20#ignorelatexjunk
139 zstyle -e ':completion:*:*:vim#' ignored-patterns \
140   'texfiles=$(echo ${PREFIX}*.tex); [[ -n "$texfiles" ]] &&
141   reply=(*.(aux|dvi|log|p(s|df)|bbl|toc|lo[tf]|latexmain)) || reply=()'
142
143 ### LOOK & FEEL
144
145 # Take advantage of $LS_COLORS for completion as well.
146 zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
147
148 # List directories first/in a separate group
149 zstyle ':completion:*' list-dirs-first yes
150
151 # Use a less ambiguous list separator
152 zstyle ':completion:*' list-separator '::'
153
154 # allow cursor-key navigation through completion set
155 zstyle ':completion:*' menu select
156
157 # always offer the original string as a completion choice
158 zstyle ':completion:*:match:*' original true
159
160 # squash multiple slashes to one, which is the unix-style
161 zstyle ':completion:*' squeeze-slashes true
162
163 # Formatting of completion menu/list
164 zstyle ':completion:*' verbose yes
165 zstyle ':completion:*' auto-description 'missing description: %d'
166 zstyle ':completion:*:descriptions' format '%B%d%b'
167 zstyle ':completion:*:messages' format '%d'
168 zstyle ':completion:*:warnings' format 'no matches for: %d'
169 zstyle ':completion:*:corrections' format "%B%d $fg[red](errors: %e)$reset_color%b"
170 #zstyle ':completion:*:matches' group 'yes'
171 zstyle ':completion:*' group-name ''
172
173 # Handle command-line options a bit differently
174 zstyle ':completion:*:options' auto-description '%d'
175 zstyle ':completion:*:options' description 'yes'
176
177 ### KEYBINDINGS
178
179 # ^x^h :: provide context help, in addition to ^x h
180 bindkey '^x^h' _complete_help
181
182 ### SPECIFIC COMMAND/CONTEXT HANDLING
183
184 # commands that take commands as arguments
185 compdef _precommand gdb
186 compdef _precommand nohup
187 compdef _precommand strace
188
189 # a couple commands don't yet have -option completion but
190 # they're generic GNU tools, so…
191 typeset -la gnu_generic_tools=(mv)
192 local c
193 for c ($gnu_generic_tools) compdef _gnu_generic $c
194
195 # custom path when expanding in the sudo context
196 zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
197                                            /usr/local/bin  \
198                                            /usr/sbin       \
199                                            /usr/bin        \
200                                            /sbin           \
201                                            /bin            \
202                                            /usr/X11R6/bin
203
204 # Completion of processes: show all user processes
205 zstyle ':completion:*:processes' command 'PS="ps -au$USER -o pid,tty,time,pcpu,cmd"; eval $PS | grep -v "$PS"'
206
207 # Integrate directory stack with cd -<tab> completion
208 zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
209
210 # Offer .. as a special-dir to completions
211 zstyle -e ':completion:*' special-dirs '[[ $PREFIX = (../)#(|.|..) ]] && reply=(..)'
212 #TODO does not yet work
213
214 # complete manual by their section
215 zstyle ':completion:*:manuals' separate-sections true
216 zstyle ':completion:*:manuals.*' insert-sections false
217
218 # debbug #527301
219 zstyle ':completion::complete:xmms2:*:values' list-grouped false
220 zstyle ':completion::complete:xmms2:*:values' sort false
221
222 # vim:ft=zsh