about summary refs log tree commit diff
path: root/Completion/Unix/Type/_dict_words
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix/Type/_dict_words')
-rw-r--r--Completion/Unix/Type/_dict_words48
1 files changed, 37 insertions, 11 deletions
diff --git a/Completion/Unix/Type/_dict_words b/Completion/Unix/Type/_dict_words
index 770319036..4928a50f0 100644
--- a/Completion/Unix/Type/_dict_words
+++ b/Completion/Unix/Type/_dict_words
@@ -1,17 +1,43 @@
 #autoload
 
-local dict dictresult dictwords j expl
+local begin end ret=1
+local -a args dict dicts dictwords expl
 
-[[ -z $words[CURRENT] ]] && return 1
+if [[ $service = dict ]]; then
+  args=( ${(kv)opt_args[(I)-([hpdauk]|-(host|port|database|noauth|user|key))]} )
+fi
 
-dictresults=(${${(f)${"$(dict -m -s prefix $words[CURRENT])":gs/    
-  / /}}:#[0-9]*matches found})
+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
 
-for j in ${dictresults}
-do
-  dict=${j%%:*}
-  dictwords=(${(z)j#*:})
+dictwords=( ${${dictwords#\"}%\"} )
+dicts=( ${${(M)dictwords:#*:}%:} )
 
-  _wanted $dict expl "words from $dict" \
-       compadd -M 'm:{a-zA-Z}={A-Za-z} r:|=*' -a "$@" - dictwords
-done
+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