6 local COMP_POINT COMP_CWORD
7 local -a COMP_WORDS COMPREPLY BASH_VERSINFO
8 local COMP_LINE="$words"
9 local -A savejobstates savejobtexts
11 (( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT-1]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX ))
12 (( COMP_CWORD = CURRENT - 1))
14 BASH_VERSINFO=( 2 05b 0 1 release )
16 savejobstates=( ${(kv)jobstates} )
17 savejobtexts=( ${(kv)jobtexts} )
19 [[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )
21 matches=( ${(f)"$(compgen $@)"} )
23 if [[ -n $matches ]]; then
24 if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
25 compset -P '*/' && matches=( ${matches##*/} )
26 compset -S '/*' && matches=( ${matches%%/*} )
27 compadd -f "${suf[@]}" -a matches && ret=0
29 compadd "${suf[@]}" -a matches && ret=0
34 if [[ ${argv[${argv[(I)default]:-0}-1]} = -o ]]; then
35 _default "${suf[@]}" && ret=0
36 elif [[ ${argv[${argv[(I)dirnames]:-0}-1]} = -o ]]; then
37 _directories "${suf[@]}" && ret=0
45 local opts prefix suffix job OPTARG OPTIND ret=1
46 local -a name res results jids
50 setopt kshglob noshglob braceexpand nokshautoload
53 a alias b builtin c command d directory e export f file
54 g group j job k keyword u user v variable
57 while getopts "o:A:G:C:F:P:S:W:X:abcdefgjkuv" name; do
59 [abcdefgjkuv]) OPTARG="${shortopts[$name]}" ;&
62 alias) results+=( "${(k)aliases[@]}" ) ;;
63 arrayvar) results+=( "${(k@)parameters[(R)array*]}" ) ;;
64 binding) results+=( "${(k)widgets[@]}" ) ;;
65 builtin) results+=( "${(k)builtins[@]}" "${(k)dis_builtins[@]}" ) ;;
68 "${(k)commands[@]}" "${(k)aliases[@]}" "${(k)builtins[@]}"
69 "${(k)functions[@]}" "${(k)reswords[@]}"
74 results+=( ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N-/) )
77 disabled) results+=( "${(k)dis_builtins[@]}" ) ;;
78 enabled) results+=( "${(k)builtins[@]}" ) ;;
79 export) results+=( "${(k)parameters[(R)*export*]}" ) ;;
82 results+=( ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N) )
85 function) results+=( "${(k)functions[@]}" ) ;;
90 setopt kshglob noshglob braceexpand
91 results+=( "${res[@]}" )
97 setopt kshglob noshglob braceexpand
98 results+=( "${res[@]}" )
100 job) results+=( "${savejobtexts[@]%% *}" );;
101 keyword) results+=( "${(k)reswords[@]}" ) ;;
103 jids=( "${(@k)savejobstates[(R)running*]}" )
104 for job in "${jids[@]}"; do
105 results+=( ${savejobtexts[$job]%% *} )
109 jids=( "${(@k)savejobstates[(R)suspended*]}" )
110 for job in "${jids[@]}"; do
111 results+=( ${savejobtexts[$job]%% *} )
114 setopt|shopt) results+=( "${(k)options[@]}" ) ;;
115 signal) results+=( "SIG${^signals[@]}" ) ;;
116 user) results+=( "${(k)userdirs[@]}" ) ;;
117 variable) results+=( "${(k)parameters[@]}" ) ;;
123 $OPTARG "${words[0]}" "${words[CURRENT-1]}" "${words[CURRENT-2]}"
124 results+=( "${COMPREPLY[@]}" )
128 results+=( ${~OPTARG} )
131 W) eval "results+=( $OPTARG )" ;;
132 C) results+=( $(eval $OPTARG) ) ;;
133 P) prefix="$OPTARG" ;;
134 S) suffix="$OPTARG" ;;
136 if [[ ${OPTARG[0]} = '!' ]]; then
137 results=( "${(M)results[@]:#${OPTARG#?}}" )
139 results=( "${results[@]:#$OPTARG}" )
145 # support for the last, `word' option to compgen. Zsh's matching does a
146 # better job but if you need to, comment this in and use compadd -U
147 #shift $(( OPTIND - 1 ))
148 #(( $# )) && results=( "${(M)results[@]:#$1*}" )
150 print -l -- "$prefix${^results[@]}$suffix"
155 local args void cmd print remove
157 zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v \
159 if [[ -n $print ]]; then
160 printf 'complete %2$s %1$s\n' "${(@kv)_comps[(R)_bash*]#* }"
161 elif [[ -n $remove ]]; then
166 compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@"
170 unfunction bashcompinit
171 autoload -Uz bashcompinit