about summary refs log tree commit diff
path: root/Completion/Unix/Type/_dict_words
blob: 4928a50f0ad2a05df19ec1d6575f6fa3f3d56006 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#autoload

local begin end ret=1
local -a args dict dicts dictwords expl

if [[ $service = dict ]]; then
  args=( ${(kv)opt_args[(I)-([hpdauk]|-(host|port|database|noauth|user|key))]} )
fi

if [[ -z $words[CURRENT] ]]; then
  _message -e dict 'dictionary word'
  return 1
elif [[ -z $SUFFIX ]]; then
  dictwords=( ${(z)${(f)"$(_call_program words dict $args -m -s prefix $PREFIX 2>/dev/null)"}} )
elif [[ -z $PREFIX ]]; then
  dictwords=( ${(z)${(f)"$(_call_program words dict $args -m -s suffix $SUFFIX 2>/dev/null)"}} )
else
  dictwords=( ${(z)${(f)"$(_call_program words dict $args -m -s regexp $PREFIX.\*$SUFFIX 2>/dev/null)"}} )
fi

dictwords=( ${${dictwords#\"}%\"} )
dicts=( ${${(M)dictwords:#*:}%:} )

if zstyle -t ":completion:${curcontext}:words" separate-sections; then
  _tags words.$^dicts
  while _tags; do
    for dict in $dicts; do
      if _requested words.$dict expl "word from $dict"; then
	(( begin=${dictwords[(i)$dict:]} + 1 ))
	end=${dictwords[(ib.begin.)*:]}
	[[ $end = 1 ]] && end=$#dictwords
	compadd "$expl[@]" "$@" -M 'm:{a-zA-Z}={A-Za-z} r:|=*' -a - \
            'dictwords[begin,end]' && ret=0
      fi
    done
    (( ret )) || break
  done
  
  return 1
else
  _wanted words expl word compadd -M 'm:{a-zA-Z}={A-Za-z} r:|=*' "$@" - \
      ${dictwords:#*:}
fi