1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-09-24 21:11:03 +02:00
zsh/Completion/Base/Utility/_regex_words
Daniel Shahaf 2ab41d508d 37215: _regex_words: Don't add mismatched parentheses
I ran into this in the wild¹, it manifested as the following error message:

    zregexparse:4: not enough regex arguments

¹ https://bug.tasktools.org/browse/TW-1729
2015-11-27 07:26:38 +00:00

50 lines
856 B
Plaintext

#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
if (( $# )); then
reply=(\()
else
# ### Is this likely to happen in callers? Should we warn?
reply=()
return
fi
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
reply+=(":${tag}:${desc}:_values -s ${(q)term} ${(q)desc} \
${(q)${${wds[1]//\*}//(#m)[:\[\]]/\\$MATCH}}\\[${(q)${wds[2]//(#m)[:\[\]]/\\$MATCH}}\\]")
fi
eval "reply+=($wds[3])"
if (( $i == $# )); then
reply+=(\))
else
reply+=(\|)
fi
done