about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2003-04-18 08:34:49 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2003-04-18 08:34:49 +0000
commited20475b5589ec6232daa04f27d95b804c62b7c6 (patch)
tree5ce4250a7d9d50b3461ec7493b8a4dd1f33921dc
parent397f465e0dec1743127789d539ad7b88443447e5 (diff)
downloadzsh-ed20475b5589ec6232daa04f27d95b804c62b7c6.tar.gz
zsh-ed20475b5589ec6232daa04f27d95b804c62b7c6.tar.xz
zsh-ed20475b5589ec6232daa04f27d95b804c62b7c6.zip
18449: complete dictionary databases and strategies, handle suffixes better and
       handle the separate-sections style for separate databases with dict words
-rw-r--r--ChangeLog4
-rw-r--r--Completion/Unix/Command/_dict62
-rw-r--r--Completion/Unix/Type/_dict_words48
3 files changed, 79 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index b07d1c5aa..c6c1160a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2003-04-18  Oliver Kiddle  <opk@zsh.org>
 
+	* 18449: Completion/Unix/Type/_dict_words,
+	Completion/Unix/Command/_dict: complete dictionary databases and
+	matching strategies and handle suffixes better
+
 	* users/6013: GoTaR <gotar@poczta.onet.pl>: Completion/Unix/Type/_ps,
 	Completion/Unix/Type/_pdf, Completion/X/Command/_gqview:
 	new gqview completion and complete .ps/.pdf files for more commands
diff --git a/Completion/Unix/Command/_dict b/Completion/Unix/Command/_dict
index b86ec4267..202fc5bab 100644
--- a/Completion/Unix/Command/_dict
+++ b/Completion/Unix/Command/_dict
@@ -1,28 +1,42 @@
 #compdef dict
 
-_arguments \
-  '(--host -h)'{--host,-h}'[host]:dict server:_hosts' \
-  '(--port -p)'{--port,-p}'[port]:service:' \
-  '(--database -d)'{--database,-d}'[database]:db name:' \
-  '(--match -m)'{--match,-m}'[match]' \
-  '(--strategy -s)'{--strategy,-s}'[strategy]:strategy:' \
-  '(--nocorrect -C)'{--nocorrect,-C}'[nocorrect]' \
-  '(--config -c)'{--config,-c}'[config]:config file:_files' \
-  '(--dbs -D)'{--dbs,-D}'[list dbs]' \
-  '(--strats -S)'{--strats,-S}'[strats]' \
-  '(--serverhelp -H)'{--serverhelp,-H}'[server help]' \
-  '(--info -i)'{--info,-i}'[db info]:db name:' \
+local strategy database state line curcontext="$curcontext"
+typeset -A opt_args
+
+_arguments -C -S \
+  '(--host -h)'{--host=,-h+}'[specify hostname of dict server]:dict server:_hosts' \
+  '(--port -p)'{--port=,-p+}'[specify port for dict server]:service:_ports' \
+  '(--database -d)'{--database=,-d+}'[database]:db name:->database' \
+  '(--match -m)'{--match,-m}'[perform matching]' \
+  '(--strategy -s)'{--strategy=,-s+}'[specify matching strategy]:strategy:->strategy' \
+  '(--nocorrect -C)'{--nocorrect,-C}'[disable spelling correction]' \
+  '(--config -c)'{--config=,-c+}'[specify config file]:config file:_files' \
+  '(--dbs -D)'{--dbs,-D}'[list available databases]' \
+  '(--strats -S)'{--strats,-S}'[list available search strategies]' \
+  '(--serverhelp -H)'{--serverhelp,-H}'[query server for help info it provides]' \
+  '(--info -i)'{--info=,-i+}'[get info on specified database]:db name:->database' \
+  '(--serverinfo -I)'{--serverinfo,-I}'[display info about server]' \
   '(--noauth -a)'{--noauth,-a}'[disable authentication]' \
-  '(--user -u)'{--user,-u}'[user]:user name:' \
-  '(--key -k)'{--key,-k}'[key]:shared secret:' \
-  '(--version -V)'{--version,-V}'[display version]' \
-  '(--license -L)'{--license,-L}'[display license]' \
-  '--help' \
-  '(--verbose -v)'{--verbose,-v}'[be verbose]' \
+  '(--user -u)'{--user=,-u+}'[specify username for authentication]:user name:' \
+  '(--key -k)'{--key=,-k+}'[specify key for authentication]:shared secret:' \
+  '(-)'{--version,-V}'[display program version]' \
+  '(-)'{--license,-L}'[display program license]' \
+  '(-)--help[display usage info]' \
+  '(--verbose -v)'{--verbose,-v}'[verbose output]' \
   '(--raw -r)'{--raw,-r}'[be very verbose]' \
-  '(--pager -P)'{--pager,-P}'[pager]:program:_command_names -e' \
-  '--html' \
-  '--pipesize:buffer size:' \
-  '--client:client text:' \
-  '--debug:debug flag:(verbose raw scan parse pipe serial time)' \
-  ':word:_dict_words'
+  '(--pager -P)'{--pager=,-P+}'[specify pager]:program:_command_names -e' \
+  '--pipesize=[specify buffer size for pipelining commands]:buffer size:' \
+  '--client=[specify additional text to send to server]:client text' \
+  '--debug=[set a debug flag]:debug flag:(verbose raw scan parse pipe serial time)' \
+  ':word:_dict_words' && return
+
+case "$state" in
+  strategy)
+    strategy=( ${${${(f)"$(_call_program strategy dict -S 2>/dev/null)"}[2,-1]#?}/ ##/:} )
+    _describe -t strategy strategy strategy && return
+  ;;
+  database)
+    database=( ${${${(f)"$(_call_program database dict --dbs 2>/dev/null)"}[2,-1]#?}/ ##/:} )
+    _describe -t database database database && return
+  ;;
+esac
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