#autoload # The main loop of the completion code. This is what is called when # completion is attempted from the command line. # If you want to complete only set or unset options for the unsetopt # and setopt builtin, un-comment these lines: # # local _set_options _unset_options # # _set_options=(${(k)options[(R)on]}) # _unset_options=(${(k)options[(R)off]}) # # This is needed because completion functions may set options locally # which makes the output of setopt and unsetopt reflect a different # state than the global one for which you are completing. local comp post ret=1 _compskip _prio_num=1 _cur_context format local context state line opt_args val_args curcontext typeset -U _offered_tags _tried_tags _failed_tags _used_tags _unused_tags _offered_tags=() _tried_tags=() _failed_tags=() typeset -U _lastdescr setopt localoptions nullglob rcexpandparam extendedglob unsetopt markdirs globsubst shwordsplit nounset ksharrays # Special completion contexts after `~' and `='. if compset -P 1 '\='; then compstate[context]=equal elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then compset -p 1 compstate[context]=tilde fi # Get the names of the completers to use in the positional parameters. if (( ! $# )); then local tmp _style -a '' completer tmp set -- "$tmp[@]" fi # And now just call the completer functions defined. for comp; do if "$comp"; then ret=0 break; fi done # See which tags were or were not used. _used_tags=( "${(@)_tried_tags:#${(j:|:)~${(@)_failed_tags//\[/\\[}//\]/\\]}}" ) _unused_tags=( "${(@)_offered_tags:#${(j:|:)~${(@)_used_tags//\[/\\[}//\]/\\]}}" ) # Now call the post-functions. for post in "$comppostfuncs[@]"; do "$post" done comppostfuncs=() _lastdescr=( "\`${(@)^_lastdescr:#}'" ) _style -s warnings format format if [[ compstate[nmatches] -eq 0 && compstate[matcher] -eq compstate[total_matchers] && -n "$format" && $#_lastdescr -ne 0 ]]; then local str compstate[list]=list compstate[force_list]=yes compstate[insert]='' case $#_lastdescr in 1) str="$_lastdescr[1]";; 2) str="$_lastdescr[1] or $_lastdescr[2]";; *) str="${(j:, :)_lastdescr[1,-2]}, or $_lastdescr[-1]";; esac compadd -UX "${format//\\%d/$str}" -n '' fi _style '' last-prompt && compstate[last_prompt]=yes _lastcomp=( "${(@kv)compstate}" ) _lastcomp[completer]="$comp" _lastcomp[prefix]="$PREFIX" _lastcomp[suffix]="$SUFFIX" _lastcomp[iprefix]="$IPREFIX" _lastcomp[isuffix]="$ISUFFIX" _lastcomp[qiprefix]="$QIPREFIX" _lastcomp[qisuffix]="$QISUFFIX" _lastcomp[offered_tags]="${(j.:.)_offered_tags}" _lastcomp[tried_tags]="${(j.:.)_tried_tags}" _lastcomp[failed_tags]="${(j.:.)_failed_tags}" _lastcomp[unused_tags]="${(j.:.)_unused_tags}" _lastcomp[used_tags]="${(j.:.)_used_tags}" return ret