about summary refs log tree commit diff
path: root/Completion/Base/Utility/_regex_words
blob: 1cc9e9ccc55872574971b692d8dfa944a8c7273a (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
44
#autoload

local opt OPTARG
local term=$'\0'

while getopts "t:" opt; do
  case $opt in
    (t)
    term=$OPTARG
    ;;

    (*)
    return 1
    ;;
  esac
done
shift $(( OPTIND - 1 ))

local tag=$1
local desc=$2
shift 2

reply=(\()

integer i
local -a wds

for (( i = 1; i <= $#; i++ )); do
  wds=(${(s.:.)argv[i]})
  reply+=(/${wds[1]//\**/"[^$term]#"}"$term"/)
  if [[ $term = $'\0' ]]; then
    reply+=(":${tag}:${desc}:(( ${wds[1]//\*}:${wds[2]//(#m)[: \(\)]/\\$MATCH} ))")
  else
    # HERE: we should add the terminator instead of a space, but
    # there doesn't appear to be an easy way of doing that.
    reply+=(":${tag}:${desc}:(( ${wds[1]//\*}${term//(#m)[: \(\)]/\\$MATCH}:${wds[2]//(#m)[: \(\)]/\\$MATCH} ))")
  fi
  eval "reply+=($wds[3])"
  if (( $i == $# )); then
    reply+=(\))
  else
    reply+=(\|)
  fi
done