]>
Commit | Line | Data |
---|---|---|
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. | |
10 | if [[ "$TERM" == 'dumb' ]]; then | |
11 | return 1 | |
12 | fi | |
13 | ||
14 | # Load and initialize the completion system ignoring insecure directories. | |
15 | autoload -Uz compinit && compinit -i | |
16 | ||
17 | # | |
18 | # Options | |
19 | # | |
20 | ||
21 | setopt COMPLETE_IN_WORD # Complete from both ends of a word. | |
22 | setopt ALWAYS_TO_END # Move cursor to the end of a completed word. | |
23 | setopt PATH_DIRS # Perform path search even on command names with slashes. | |
24 | setopt AUTO_MENU # Show completion menu on a successive tab press. | |
25 | setopt AUTO_LIST # Automatically list choices on ambiguous completion. | |
26 | setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash. | |
27 | unsetopt MENU_COMPLETE # Do not autoselect the first completion entry. | |
28 | unsetopt 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. | |
35 | zstyle ':completion::complete:*' use-cache on | |
36 | zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache" | |
37 | ||
38 | zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' | |
39 | unsetopt CASE_GLOB | |
40 | ||
41 | # Group matches and describe. | |
42 | zstyle ':completion:*:*:*:*:*' menu select | |
43 | zstyle ':completion:*:matches' group 'yes' | |
44 | zstyle ':completion:*:options' description 'yes' | |
45 | zstyle ':completion:*:options' auto-description '%d' | |
46 | zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f' | |
47 | zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f' | |
48 | zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f' | |
49 | zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f' | |
50 | zstyle ':completion:*:default' list-prompt '%S%M matches%s' | |
51 | zstyle ':completion:*' format ' %F{yellow}-- %d --%f' | |
52 | zstyle ':completion:*' group-name '' | |
53 | zstyle ':completion:*' verbose yes | |
54 | ||
55 | # Fuzzy match mistyped completions. | |
56 | zstyle ':completion:*' completer _complete _match _approximate | |
57 | zstyle ':completion:*:match:*' original only | |
58 | zstyle ':completion:*:approximate:*' max-errors 1 numeric | |
59 | ||
60 | # Increase the number of errors based on the length of the typed word. | |
61 | zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' | |
62 | ||
63 | # Don't complete unavailable commands. | |
64 | zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))' | |
65 | ||
66 | # Array completion element sorting. | |
67 | zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters | |
68 | ||
69 | # Directories | |
70 | zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} | |
71 | zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories | |
72 | zstyle ':completion:*:*:cd:*:directory-stack' menu yes select | |
73 | zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand' | |
74 | zstyle ':completion:*' squeeze-slashes true | |
75 | ||
76 | # History | |
77 | zstyle ':completion:*:history-words' stop yes | |
78 | zstyle ':completion:*:history-words' remove-all-dups yes | |
79 | zstyle ':completion:*:history-words' list false | |
80 | zstyle ':completion:*:history-words' menu yes | |
81 | ||
82 | # Environmental Variables | |
83 | zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-} | |
84 | ||
85 | # Populate hostname completion. | |
86 | zstyle -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... | |
93 | zstyle ':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. | |
103 | zstyle '*' single-ignored show | |
104 | ||
105 | # Ignore multiple entries. | |
106 | zstyle ':completion:*:(rm|kill|diff):*' ignore-line other | |
107 | zstyle ':completion:*:rm:*' file-patterns '*:all-files' | |
108 | ||
109 | # Kill | |
110 | zstyle ':completion:*:*:*:*:processes' command 'ps -u $LOGNAME -o pid,user,command -w' | |
111 | zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01' | |
112 | zstyle ':completion:*:*:kill:*' menu yes select | |
113 | zstyle ':completion:*:*:kill:*' force-list always | |
114 | zstyle ':completion:*:*:kill:*' insert-ids single | |
115 | ||
116 | # Man | |
117 | zstyle ':completion:*:manuals' separate-sections true | |
118 | zstyle ':completion:*:manuals.(^1*)' insert-sections true | |
119 | ||
120 | # SSH/SCP/RSYNC | |
121 | zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' | |
122 | zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr | |
123 | zstyle ':completion:*:ssh:*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' | |
124 | zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr | |
125 | zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost | |
126 | zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' | |
127 | zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*' |