@@ -272,17 +272,19 @@ _upvars()
272272#
273273# Options:
274274# -E $2 is interpreted as a POSIX extended regular expression.
275- # This is always the partial matching unless ^, $ is included
276- # in $2.
277- # -F $2 is interpreted as a fixed string.
278- # -G $2 is interpreted as a glob pattern.
279- #
280- # -p Combined with -F or -G, it performs the prefix matching.
281- # -s Combined with -F or -G, it performs the suffix matching.
282- # -m Combined with -F or -G, it performs the middle matching.
275+ # The default anchoring is `-m` (see below).
276+ # -F $2 is interpreted as a fixed string. The default anchoring
277+ # is `-m` (see below).
278+ # -G $2 is interpreted as a glob pattern. The default anchoring
279+ # is `-x` (see below).
280+ #
281+ # -p Combined with -EFG, it performs the prefix matching.
282+ # -s Combined with -EFG, it performs the suffix matching.
283+ # -m Combined with -EFG, it performs the middle matching.
284+ # -x Combined with -EFG, it performs the exact matching.
285+ #
283286# -r Revert the condition, i.e., remove elements that satisfy
284287# the original condition.
285- #
286288# -C Array compaction is not performed.
287289#
288290# @return 2 with a wrong usage, 1 when any elements are removed, 0 when the set
@@ -293,14 +295,14 @@ _comp_array_filter()
293295{
294296 local _comp_local_flags=' ' _comp_local_pattype=' ' _comp_local_anchoring=' '
295297 local OPTIND=1 OPTARG=' ' OPTERR=0 _comp_local_opt=' '
296- while getopts ' EFGpsmrC ' _comp_local_opt " $@ " ; do
298+ while getopts ' EFGpsmxrC ' _comp_local_opt " $@ " ; do
297299 case $_comp_local_opt in
298300 [EFG]) _comp_local_pattype=$_comp_local_opt ;;
299- [psm ]) _comp_local_anchoring=$_comp_local_opt ;;
301+ [psmx ]) _comp_local_anchoring=$_comp_local_opt ;;
300302 [rC]) _comp_local_flags=$_comp_local_opt$_comp_local_flags ;;
301303 * )
302304 printf ' bash_completion: %s: %s\n' " $FUNCNAME " ' usage error' >&2
303- printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmrC ] ARRAY_NAME CONDITION" >&2
305+ printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmxrC ] ARRAY_NAME CONDITION" >&2
304306 return 2
305307 ;;
306308 esac
@@ -309,7 +311,7 @@ _comp_array_filter()
309311 shift $(( OPTIND - 1 ))
310312 if (( $# != 2 )) ; then
311313 printf ' bash_completion: %s: %s\n' " $FUNCNAME " " unexpected number of arguments: $# " >&2
312- printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmrC ] ARRAY_NAME CONDITION" >&2
314+ printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmxrC ] ARRAY_NAME CONDITION" >&2
313315 return 2
314316 elif [[ $1 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
315317 printf ' bash_completion: %s: %s\n' " $FUNCNAME " " invalid array name '$1 '." >&2
@@ -327,14 +329,19 @@ _comp_array_filter()
327329 local _comp_local_predicate=' ' _comp_local_pattern=$2
328330 case $_comp_local_pattype in
329331 E)
330- _comp_local_predicate=' [[ $_comp_local_value =~ $_comp_local_pattern ]]'
332+ case $_comp_local_anchoring in
333+ p) _comp_local_predicate=' [[ $_comp_local_value =~ ^($_comp_local_pattern) ]]' ;;
334+ s) _comp_local_predicate=' [[ $_comp_local_value =~ ($_comp_local_pattern)$ ]]' ;;
335+ x) _comp_local_predicate=' [[ $_comp_local_value =~ ^($_comp_local_pattern)$ ]]' ;;
336+ * ) _comp_local_predicate=' [[ $_comp_local_value =~ $_comp_local_pattern ]]' ;;
337+ esac
331338 ;;
332339 F)
333340 case $_comp_local_anchoring in
334341 p) _comp_local_predicate=' [[ $_comp_local_value == "$_comp_local_pattern"* ]]' ;;
335342 s) _comp_local_predicate=' [[ $_comp_local_value == *"$_comp_local_pattern" ]]' ;;
336- m ) _comp_local_predicate=' [[ $_comp_local_value == * "$_comp_local_pattern"* ]]' ;;
337- * ) _comp_local_predicate=' [[ $_comp_local_value == "$_comp_local_pattern" ]]' ;;
343+ x ) _comp_local_predicate=' [[ $_comp_local_value == "$_comp_local_pattern" ]]' ;;
344+ * ) _comp_local_predicate=' [[ $_comp_local_value == * "$_comp_local_pattern"* ]]' ;;
338345 esac
339346 ;;
340347 G)
0 commit comments