diff options
author | Oliver Kiddle <opk@users.sourceforge.net> | 2003-04-18 08:34:49 +0000 |
---|---|---|
committer | Oliver Kiddle <opk@users.sourceforge.net> | 2003-04-18 08:34:49 +0000 |
commit | ed20475b5589ec6232daa04f27d95b804c62b7c6 (patch) | |
tree | 5ce4250a7d9d50b3461ec7493b8a4dd1f33921dc /Completion/Unix/Type | |
parent | 397f465e0dec1743127789d539ad7b88443447e5 (diff) | |
download | zsh-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
Diffstat (limited to 'Completion/Unix/Type')
-rw-r--r-- | Completion/Unix/Type/_dict_words | 48 |
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 |