26763: fix problem on failed cd -s to relative path
[zsh.git] / Completion / Zsh / Command / _zstyle
blob008061978a3486320b2b5667612e4c66db07d258
1 #compdef zstyle
3 local state context ostate line expl ctop suf
4 local nm=$compstate[nmatches] taglist patterns pstyles
5 typeset -A opt_args styles
7 (( $+functions[_completers] )) ||
8 _completers() {
9   # option: -p - needs a `_' prefix
10   local us
11   local -a disp list expl
12   
13   list=( complete approximate correct match expand list menu oldlist
14          ignored prefix history )
15   zparseopts -D -K -E 'p=us'
16   [[ -n "$us" ]] && us='_'
17   zstyle -t ":completion:${curcontext}:completers" prefix-hidden &&
18       disp=(-d list)
19   _wanted completers expl 'completer' \
20       compadd "$@" "$disp[@]" - "$us${^list[@]}"
23 # Assoc array of styles; the values give the possible top-level
24 # contexts:
25 #   c   completion
26 #   e   line editor
27 #   z   zftp
28 # or any combination of the above,
29 # followed by a colon, followed by a state to enter, empty if none.
30 styles=(
31   accept-exact           c:bool
32   accept-exact-dirs      c:bool
33   add-space              c:bool
34   ambiguous              c:bool
35   assign-list            c:_parameters
36   auto-description       c:
37   avoid-completer        c:completer
38   break-keys             c:
39   cache-path             c:_directories
40   cache-policy           c:_functions
41   call-command           c:bool
42   command                c:command
43   commands               c:
44   complete               c:bool
45   completer              c:completer
46   condition              c:bool
47   cursor                 c:cursor
48   disabled               c:bool
49   domains                c:
50   expand                 c:
51   fake-files             c:fake-files
52   fake-parameters        c:fake-params
53   file-list              c:bool
54   file-patterns          c:filepat
55   file-sort              c:fsort
56   filter                 c:
57   force-list             c:
58   format                 c:
59   glob                   c:bool
60   global                 c:bool
61   group-name             c:
62   group-order            c:tag
63   groups                 c:_groups
64   hidden                 c:bool
65   hosts                  c:_hosts
66   hosts-ports            c:host-port
67   ignore-line            c:ignline
68   ignore-parents         c:ignorepar
69   ignored-patterns       c:
70   insert-ids             c:insert-ids
71   insert-tab             c:bool
72   insert-unambiguous     c:insunambig
73   keep-prefix            c:keep-prefix
74   last-prompt            c:bool
75   list                   ce:listwhen
76   list-colors            c:
77   list-dirs-first        c:bool
78   list-grouped           c:bool
79   list-packed            c:bool
80   list-prompt            c:
81   list-rows-first        c:bool
82   list-separator         c:separator
83   list-suffixes          c:bool
84   local                  c:
85   mail-directory         c:_directories
86   match-original         c:match-orig
87   matcher                c:
88   matcher-list           c:
89   max-errors             c:
90   max-matches-width      c:max-matches-width
91   menu                   c:boolauto
92   muttrc                 c:_files
93   numbers                c:bool
94   old-list               c:bool
95   old-matches            c:oldmatches
96   old-menu               c:bool 
97   original               c:bool
98   packageset             c:packageset
99   path                   c:_directories
100   pager                  c:_command_names
101   pine-directory         c:_directories
102   ports                  c:_ports
103   prefix-hidden          c:bool
104   prefix-needed          c:bool
105   preserve-prefix        c:preserve-prefix
106   range                  c:
107   regular                c:bool
108   remote-access          c:bool
109   remove-all-dups        c:bool
110   select-prompt          c:
111   select-scroll          c:
112   separate-sections      c:bool
113   single-ignored         c:single-ignored
114   sort                   c:bool
115   special-dirs           c:sdirs
116   squeeze-slashes        c:bool
117   stop                   c:stop
118   stop-keys              c:
119   strip-comments         c:bool
120   subst-globs-only       c:bool
121   substitute             c:bool
122   suffix                 c:bool
123   tag-order              c:tag-order
124   try-to-use-pminst      c:bool
125   urls                   c:_urls
126   use-cache              c:bool
127   use-compctl            c:urgh
128   users                  c:_users
129   users-hosts            c:user-host
130   users-hosts-ports      c:user-host-port
131   verbose                ce:bool
132   word                   c:bool
134   auto-previous          e:bool
135   break-keys             e:
136   cursor                 e:
137   edit-buffer            e:bool
138   edit-previous          e:bool
139   insert-kept            e:
140   leave-cursor           e:bool
141   match                  e:
142   prompt                 e:
143   stop-keys              e:
144   toggle                 e:bool
145   url-globbers           e:
146   url-local-schema       e:
147   url-metas              e:
148   url-other-schema       e:
149   url-seps               e:
150   whence                 e:
151   word-chars             e:
152   word-style             e:word-style
153   word-context           e:
155   chpwd                  z:bool
156   progress               z:progress
157   remote-glob            z:bool
158   titlebar               z:bool
159   update                 z:
162 taglist=(
163   accounts all-expansions all-files arguments arrays association-keys
164   bookmarks builtins characters colormapids colors commands contexts
165   corrections cursors default descriptions devices directories
166   directory-stack displays expansions extensions files flags fstypes
167   fonts functions globbed-files groups history-words hosts indexes
168   interfaces jobs keymaps keysyms libraries limits local-directories
169   mailboxes manuals maps messages modifiers modules my-accounts
170   named-directories names newsgroups nicknames options original
171   other-accounts packages parameters path-directories paths pods ports
172   prefixes printers processes processes-names ps regex sequences
173   sessions signals strings styles tags targets timezones types urls
174   users values variant visuals warnings widgets windows zsh-options
175   email-address ${(k)functions[(I)_email-*]#_}
178 _arguments -C \
179   '(-)-L[output in form of zstyle commands]' \
180   '(: -)-d[delete style definitions]:context pattern:->patterns:*:styles:->pstyles' \
181   '(-)-e[value is evaluated when style is looked up]' \
182   ':context:->contexts' ':style:->styles' '*:argument:->style-arg'
184 while (( $#state )); do
185   case "$state[1]" in
186     (contexts)
187       if [[ ! -prefix :*: ]]; then
188         _wanted contexts expl context compadd -P : -S : completion zftp
189       elif compset -P :completion:; then
190         for ostate in functions _completers cmdorcont argument tag; do
191           compset -P '[^:]#:' || break
192         done
193         suf=()
194         compset -S ':*' || suf=( -qS: )
195         [[ $ostate = tag ]] && suf=()
196         if compset -P '(|\\)\((*\||)'; then  # handle (x|y) patterns
197           suf=()
198           compset -S '(|\\)[)|]*' ||
199               suf=( -S "${${QIPREFIX:+|}:-\|}" -r "${${QIPREFIX:+|}:-\\\\} \t)" )
200         fi
201         state+=( "$ostate" )
202       fi
203       ;;
205     (patterns)
206       zstyle -g patterns
207       _wanted contexts expl 'context pattern' compadd -a patterns
208       ;;
210     (pstyles)
211       zstyle -g pstyles ${(Q)${(M)opt_args[-d]#*[^\\]:}%:}
212       _wanted styles expl style compadd -a pstyles
213     ;;
215     (styles)
216       # Get the top-level context we're completing for, if any.
217       case $line[1] in
218         (:completion:*)
219         ctop=c
220         ;;
222         (:zftp:*)
223         ctop=z
224         ;;
226         (:zle:*)
227         ctop=e
228         ;;
230         (*)
231         ctop=cez
232         ;;
233       esac
234       _wanted styles expl style \
235          compadd -M 'r:|-=* r:|=*' -k "styles[(R)[^:]#[$ctop][^:]#:*]"
236       ;;
238     (style-arg)
239       state+=( "${styles[$line[2]]#*:}" )
240       ;;
242     (argument)
243       _message -e arguments argument
244       ;;
246     (bool)
247       _wanted values expl boolean compadd true false
248       ;;
250     (boolauto)
251       _wanted values expl boolean \
252           compadd true false auto select search search-backward interactive
253       ;;
255     (cmdorcont)
256       _alternative -O suf \
257         'commands:command:_command ' \
258         'contexts:context:(-array-value- -brace-parameter- -command- -condition- -math- -parameter- -redirect- -subscript- -value-)'
259      ;;
261     (cursor)
262       _wanted values expl 'cursor positioning' compadd complete key default
263       ;;
265     (completer)
266       _wanted values expl completer _completers -p
267       ;;
269     (fsort)
270       _wanted values expl 'how to sort files' \
271         compadd name size links time date modification access inode change reverse
272       ;;
274     (function)
275       _wanted control-function expl 'control function' \
276           compadd predict-on all-matches
277       ;;
279     (functions)
280       _wanted comp-widget expl 'completion widget' \
281           compadd $suf - all-matches complete-debug complete-tag \
282           correct-word expand-word expand-alias-word history-words
283       ;;
285     (user-host-port)
286       if [[ $PREFIX != *[@:]* ]]; then
287         _users -S @
288       elif [[ $PREFIX = *[@:]*[[@:]* ]]; then
289         compset -P 2 '*[:@]'
290         _ports
291       else
292         compset -P 1 '*[:@]'
293         _hosts -S :
294       fi
295       ;;
297     (host-port)
298       if [[ $PREFIX != *:* ]]; then
299         _hosts -S :
300       else
301         compset -P 1 '*:'
302         _ports
303       fi
304       ;;
306     (listwhen)
307       _wanted values expl 'when to list completions' \
308         compadd always never sometimes
309       ;;
311     (packageset)
312       _wanted values expl 'default package set' \
313         compadd available installed uninstalled
314       ;;
316     (progress)
317       _wanted values expl 'progress meter style' \
318         compadd none bar percent
319       ;;
321     (sdirs)
322       _wanted values expl 'whether to complete . or ..' \
323         compadd true false ..
324       ;;
326     (stop)
327       _wanted values expl 'when to insert matches' \
328         compadd true false verbose
329       ;;
331     (tag)
332       _wanted tags expl tag compadd $suf -a taglist
333       ;;
335     (tag-order)
336       if compset -P '*:*:'; then
337         _message -e descriptions description
338       elif compset -P '*:'; then
339         _message -e labels 'tag label'
340       else
341         suf=()
342         compset -S ':*' || suf=( -qS: )
343         _wanted values expl tag compadd $suf -a taglist
344       fi
345       ;;
347     (filepat)
348       if compset -P '*:*:'; then
349         _message -e descriptions description
350       elif compset -P '*:'; then
351         _message -e tags tag
352       else
353         _message -e patterns 'glob patterns'
354       fi
355       ;;
357     (user-host)
358       if [[ $PREFIX = *[@:]* ]]; then
359         compset -P '*[@:]'
360         _hosts
361       else
362         _users -S @
363       fi
364       ;;
366     (ignorepar)
367       _wanted values expl 'which parents to ignore' \
368         compadd parent pwd .. directory
369       ;;
371     (single-ignored)
372       _wanted values expl 'how to handle a single ignored match' \
373           compadd - show menu
374       ;;
376     (command)
377       shift 3 words
378       (( CURRENT -= 3 ))
379       _normal
380       ;;
382     (insert-ids)
383       _wanted values expl 'when to insert process IDs' \
384           compadd - menu single longer
385       ;;
387     (fake-files)
388       _message -e fakes 'prefix and names'
389       ;;
391     (fake-params)
392       if compset -P '*:'; then
393         _wanted values expl 'parameter type' compadd scalar array integer
394       else
395         suf=''
396         compset -S ':*' || suf='-qS:'
397         _wanted values expl 'fake parameter' _parameters $suf
398       fi
399       ;;
401     (ignline)
402       _wanted values expl 'ignore strings on the line' compadd true false current current-shown other
403       ;;
405     (keep-prefix)
406       _wanted values expl 'keep prefix' compadd true false changed
407       ;;
409     (match-orig)
410       _wanted values expl "match without inserting \`*'" compadd only both
411       ;;
413     (oldmatches)
414       _wanted values expl 'use list of old matches' compadd true false only
415       ;;
417     (insunambig)
418       _wanted values expl 'insert unambiguous string' compadd true false pattern
419       ;;
421     (preserve-prefix)
422       _message -e prefixes 'pattern matching prefix to keep'
423       ;;
425     (separator)
426       _message -e separators 'separator string'
427       ;;
429     (max-matches-width)
430       _message -e numbers 'maximum display width for matches'
431       ;;
433     (urgh)
434       _wanted values expl no compadd no false off 0
435       ;;
437     (word-style)
438       _wanted word-styles expl 'word style' compadd normal shell space
439       ;;
441     (_*)
442       ${=state[1]} $suf
443       ;;
444   esac
445   shift state
446 done
448 [[ $compstate[nmatches] != $nm ]]